/*
 * Copyright (c) 2017-2025 The Forge Interactive Inc.
 *
 * This file is part of The-Forge
 * (see https://github.com/ConfettiFX/The-Forge).
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#include "../../Application/Config.h"

/// start file generated from microprofile.html
#ifdef PROFILE_EMBED_HTML
const char g_ProfileHtml_begin_0[] =
    "<!DOCTYPE HTML>\n"
    "<html>\n"
    "<head>\n"
    "<title>Profile Capture</title>\n"
    "<style>\n"
    "/* about css: http://bit.ly/1eMQ42U */\n"
    "body {margin: 0px;padding: 0px; font: 12px Courier New;background-color:#474747; color:white;overflow:hidden;}\n"
    "ul {list-style-type: none;margin: 0;padding: 0;}\n"
    "li{display: inline; float:left;border:5px; position:relative;text-align:center;}\n"
    "a {\n"
    "    float:left;\n"
    "    text-decoration:none;\n"
    "    display: inline;\n"
    "    text-align: center;\n"
    "	padding:5px;\n"
    "	padding-bottom:0px;\n"
    "	padding-top:0px;\n"
    "    color: #FFFFFF;\n"
    "    background-color: #474747;\n"
    "}\n"
    "a:hover, a:active{\n"
    "	background-color: #000000;\n"
    "}\n"
    "\n"
    "ul ul {\n"
    "    position:absolute;\n"
    "    left:0;\n"
    "    top:100%;\n"
    "    margin-left:-999em;\n"
    "}\n"
    "li:hover ul {\n"
    "    margin-left:0;\n"
    "    margin-right:0;\n"
    "}\n"
    "ul li ul{ display:block;float:none;width:100%;}\n"
    "ul li ul li{ display:block;float:none;width:100%;}\n"
    "li li a{ display:block;float:none;width:100%;text-align:left;}\n"
    "#nav li:hover div {margin-left:0;}\n"
    ".help {position:fixed;z-index:5;text-align:left;padding:2px;margin-left:-999em;background-color: #313131;width:300px;}\n"
    ".helpstart {position:fixed;z-index:5;text-align:left;padding:2px;background-color: #313131;width:300px;display:block}\n"
    ".root {z-index:1;position:absolute;top:0px;left:0px;}\n"
    ".filterinput0{position:fixed;bottom:10px;left:25px;background-color: #313131}\n"
    ".filterinput1{position:fixed;bottom:10px;left:175px;background-color: #313131}\n"
    "</style>\n"
    "</head>\n"
    "<body style=\"\">\n"
    "<div id=\'filterinput\'>\n"
    "<div class=\"filterinput0\">Group<br><input type=\"text\" id=\"filtergroup\"></div>\n"
    "<div class=\"filterinput1\">Timer/Thread<br><input type=\"text\" id=\"filtertimer\"></div>\n"
    "</div>\n"
    "<canvas id=\"History\" height=\"70\" style=\"background-color:#474747;margin:0px;padding:0px;\"></canvas><canvas id=\"DetailedView\" "
    "height=\"200\" style=\"background-color:#474747;margin:0px;padding:0px;\"></canvas>\n"
    "<div id=\"root\" class=\"root\">\n"
    "<ul id=\"nav\">\n"
    "<li><a href=\"javascript:void(0)\" onclick=\"ToggleDebugMode();\">?</a>\n"
    "<div class=\"helpstart\" id=\"helpwindow\" style=\"left:20px;bottom:20px\">\n"
    "History View:<br>\n"
    "Click + Drag: Pan View<br>\n"
    "Right Click + Drag : Zoom on region<br>\n"
    "Click Frame : Center on frame<br>\n"
    "<hr>\n"
    "Main View:<br>\n"
    "Ctrl + Mouse up/down: Zoom<br>\n"
    "Mousewheel : Zoom<br>\n"
    "Right Click + Drag: Select region<br>\n"
    "Ctrl + Shift + Drag: Select region<br>\n"
    "Space: Zoom to Selection<br>\n"
    "Ctrl + Drag: Pan<br>\n"
    "Click + Drag: Pan<br>\n"
    "alt or z: Toggle ToolTip<br>\n"
    "<hr>\n"
    "Detailed View:<br>\n"
    "Tab: Go To Worst Instance<br>\n"
    "Left/Right Arrow: Next/Prev Instance<br>\n"
    "<hr>\n"
    "Timer Views:<br>\n"
    "Tab: go to filtering<br>\n"
    "Esc: Exit &amp; Clear filter\n"
    "<hr>\n"
    "<table style=\"width:100%\">\n"
    "<tr>\n"
    "<td width=\"50%\" align=\"left\"><a href=\'javascript:void(0)\' onclick=\"ShowHelp(0, 0);\">Close</a></td>\n"
    "</tr>\n"
    "</table>\n"
    "</div>\n"
    "<div class=\"help\" id=\"divFrameInfo\" style=\"left:20px;top:20px;width:auto;\">\n"
    "</div>\n"
    "</li>\n"
    "<li><a id=\'ModeSubMenuText\'>Mode</a>\n"
    "    <ul id=\'ModeSubMenu\'>\n"
    "		<li><a href=\"javascript:void(0)\" onclick=\"SetMode(\'timers\', 0);\" id=\"buttonTimers\">Timers</a></li>\n"
    "		<li><a href=\"javascript:void(0)\" onclick=\"SetMode(\'timers\', 1);\" id=\"buttonGroups\">Groups</a></li> \n"
    "		<li><a href=\"javascript:void(0)\" onclick=\"SetMode(\'timers\', 2);\" id=\"buttonThreads\">Threads</a></li>\n"
    "		<li><a href=\"javascript:void(0)\" onclick=\"SetMode(\'detailed\', 0);\" id=\"buttonDetailed\">Detailed</a></li>\n"
    "		<li><a href=\"javascript:void(0)\" onclick=\"SetMode(\'counters\', 0);\" id=\"buttonCounters\">Counters</a></li>\n"
    "	</ul>\n"
    "</li>\n"
    "<li><a>Reference</a>\n"
    "    <ul id=\'ReferenceSubMenu\'>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'5ms\');\">5ms</a></li>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'10ms\');\">10ms</a></li>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'15ms\');\">15ms</a></li>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'20ms\');\">20ms</a></li>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'33ms\');\">33ms</a></li>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'50ms\');\">50ms</a></li>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'100ms\');\">100ms</a></li>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'250ms\');\">250ms</a></li>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'500ms\');\">500ms</a></li>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"SetReferenceTime(\'1000ms\');\">1000ms</a></li>\n"
    "    </ul>\n"
    "</li>\n"
    "<li id=\"ilThreads\"><a>Threads</a>\n"
    "    <ul id=\"ThreadSubMenu\">\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"ToggleThread();\">All</a></li>\n"
    "        <li><a>---</a></li>\n"
    "    </ul>\n"
    "</li>\n"
    "<li id=\"ilGroups\"><a>Groups</a>\n"
    "    <ul id=\"GroupSubMenu\">\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"ToggleGroup();\">All</a></li>\n"
    "        <li><a>---</a></li>\n"
    "    </ul>\n"
    "</li>\n"
    "<li id=\"ilOptions\"><a>Options&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>\n"
    "    <ul id=\'OptionsMenu\'>\n"
    "        <li><a href=\"javascript:void(0)\" onclick=\"ToggleContextSwitch();\">Context Switch</a></li>\n"
    "		<li><a href=\"javascript:void(0)\" onclick=\"ToggleDisableMerge();\">MergeDisable</a></li>\n"
    "		<li><a href=\"javascript:void(0)\" onclick=\"ToggleDisableLod();\">LodDisable</a></li>\n"
    "		<li id=\'GroupColors\'><a href=\"javascript:void(0)\" onclick=\"ToggleGroupColors();\">Group Colors</a></li>\n"
    "        <li id=\'TimersMeta\'><a href=\"javascript:void(0)\" onclick=\"ToggleTimersMeta();\">Meta</a></li>\n"
    "        <li id=\'ShowHelp\'><a href=\"javascript:void(0)\" onclick=\"ShowHelp(1,1);\">Help</a></li>\n"
    "<!--      	<li><a href=\"javascript:void(0)\" onclick=\"ToggleDebug();\">DEBUG</a></li> -->\n"
    "    </ul>\n"
    "</li>\n"
    "</ul>\n"
    "</div>\n"
    "<script>\n"
    "function InvertColor(hexTripletColor) {\n"
    "	var color = hexTripletColor;\n"
    "	color = color.substring(1); // remove #\n"
    "	color = parseInt(color, 16); // convert to integer\n"
    "	var R = ((color >> 16) % 256)/255.0;\n"
    "	var G = ((color >> 8) % 256)/255.0;\n"
    "	var B = ((color >> 0) % 256)/255.0;\n"
    "	var lum = (0.2126*R + 0.7152*G + 0.0722*B);\n"
    "	if(lum < 0.7)\n"
    "	{\n"
    "		return \'#ffffff\';\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		return \'#333333\';\n"
    "	}\n"
    "}\n"
    "function InvertColorIndex(hexTripletColor) {\n"
    "	var color = hexTripletColor;\n"
    "	color = color.substring(1); // remove #\n"
    "	color = parseInt(color, 16); // convert to integer\n"
    "	var R = ((color >> 16) % 256)/255.0;\n"
    "	var G = ((color >> 8) % 256)/255.0;\n"
    "	var B = ((color >> 0) % 256)/255.0;\n"
    "	var lum = (0.2126*R + 0.7152*G + 0.0722*B);\n"
    "	if(lum < 0.7)\n"
    "	{\n"
    "		return 0;\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		return 1;\n"
    "	}\n"
    "}\n"
    "function MakeGroup(id, name, category, numtimers, isgpu, total, average, max, color)\n"
    "{\n"
    "	var group = {\"id\":id, \"name\":name, \"category\":category, \"numtimers\":numtimers, \"isgpu\":isgpu, \"total\": total, "
    "\"average\" : average, \"max\" : max, \"color\":color};\n"
    "	return group;\n"
    "}\n"
    "\n"
    "function MakeTimer(id, name, group, color, colordark, average, max, min, exclaverage, exclmax, callaverage, callcount, total, meta, "
    "metaagg, metamax)\n"
    "{\n"
    "	var timer = {\"id\":id, \"name\":name, \"namelabel\":name.startsWith(\"$\"), \"color\":color, "
    "\"colordark\":colordark,\"timercolor\":color, \"textcolor\":InvertColor(color), \"group\":group, \"average\":average, \"max\":max, "
    "\"min\":min, \"exclaverage\":exclaverage, \"exclmax\":exclmax, \"callaverage\":callaverage, \"callcount\":callcount, \"total\":total, "
    "\"meta\":meta, \"textcolorindex\":InvertColorIndex(color), \"metaagg\":metaagg, \"metamax\":metamax, \"worst\":0, \"worststart\":0, "
    "\"worstend\":0};\n"
    "	return timer;\n"
    "}\n"
    "\n"
    "function MakeTimes(scale, ts)\n"
    "{\n"
    "	for(var i = 0; i < ts.length; ++i)\n"
    "	{\n"
    "		ts[i] *= scale;\n"
    "	}\n"
    "	return ts;\n"
    "}\n"
    "\n"
    "function MakeTimesExtra(scale, scaleextra, tt, ts)\n"
    "{\n"
    "	for(var i = 0; i < ts.length; ++i)\n"
    "	{\n"
    "		ts[i] *= (tt[i] == 4) ? scaleextra : scale;\n"
    "	}\n"
    "	return ts;\n"
    "}\n"
    "\n"
    "function MakeFrame(id, framestart, frameend, framestartgpu, frameendgpu, ts, tt, ti, tl)\n"
    "{\n"
    "	var frame = {\"id\":id, \"framestart\":framestart, \"frameend\":frameend, \"framestartgpu\":framestartgpu, "
    "\"frameendgpu\":frameendgpu, \"ts\":ts, \"tt\":tt, \"ti\":ti, \"tl\":tl};\n"
    "	return frame;\n"
    "}\n"
    "\n"
    "function MakeCounter(id, parent, sibling, firstchild, level, name, value, minvalue, maxvalue, formatted, limit, formattedlimit, "
    "format, counterprc, boxprc, historydata)\n"
    "{\n"
    "	var historyprcoffset = (minvalue < 0) ? -minvalue : 0;\n"
    "	var historyprcscale = 1 / (maxvalue + historyprcoffset);\n"
    "\n"
    "	var historyprc = new Array(historydata.length);\n"
    "	for(var i = 0; i < historydata.length; ++i)\n"
    "	{\n"
    "		historydata[i] += minvalue;\n"
    "		historyprc[i] = (historydata[i] + historyprcoffset) * historyprcscale;\n"
    "	}\n"
    "\n"
    "	var counter = { \"id\":id, \"parent\":parent, \"sibling\":sibling, \"firstchild\":firstchild, \"level\": level, \"name\":name, "
    "\"value\":value, \"formatted\":formatted, \"limit\":limit, \"formattedlimit\":formattedlimit, \"format\":format, "
    "\"counterprc\":counterprc, \"boxprc\":boxprc, \"historyprc\": historyprc, \"historydata\":historydata, \"minvalue\":minvalue, "
    "\"maxvalue\":maxvalue};\n"
    "	return counter;\n"
    "}\n"
    "\n"
    "\n"
    "";

const size_t g_ProfileHtml_begin_0_size = sizeof(g_ProfileHtml_begin_0);
const char*  g_ProfileHtml_begin[] = {
    &g_ProfileHtml_begin_0[0],
};
size_t g_ProfileHtml_begin_sizes[] = {
    sizeof(g_ProfileHtml_begin_0),
};
size_t     g_ProfileHtml_begin_count = 1;
const char g_ProfileHtml_end_0[] =
    "\n"
    "\n"
    "var CanvasDetailedView = document.getElementById(\'DetailedView\');\n"
    "var CanvasHistory = document.getElementById(\'History\');\n"
    "var CanvasDetailedOffscreen = document.createElement(\'canvas\');\n"
    "var FilterInputGroup = document.getElementById(\'filtergroup\');\n"
    "var FilterInputTimer = document.getElementById(\'filtertimer\');\n"
    "var FilterInputGroupString = null;\n"
    "var FilterInputTimerString = null;\n"
    "var FilterInputArray = [FilterInputGroup, FilterInputTimer];\n"
    "var FilterGroup = null;\n"
    "var FilterTimer = null;\n"
    "var g_Msg = \'0\';\n"
    "\n"
    "var Initialized = 0;\n"
    "var fDetailedOffset = Frames[0].framestart;\n"
    "var fDetailedRange = Frames[0].frameend - fDetailedOffset;\n"
    "var nWidth = CanvasDetailedView.width;\n"
    "var nHeight = CanvasDetailedView.height;\n"
    "var ReferenceTime = 33;\n"
    "var nHistoryHeight = 70;\n"
    "var nOffsetY = 0;\n"
    "var nOffsetBarsX = 0;\n"
    "var nOffsetBarsY = 0;\n"
    "var nOffsetCountersY = 0;\n"
    "var nBarsWidth = 80;\n"
    "var NameWidth = 200;\n"
    "var MouseButtonState = [0,0,0,0,0,0,0,0];\n"
    "var KeyShiftDown = 0;\n"
    "var MouseDragButton = 0;\n"
    "var KeyCtrlDown = 0;\n"
    "var ToolTip = 1; //0: off, 1: default, 2: flipped\n"
    "var DetailedViewMouseX = 0;\n"
    "var DetailedViewMouseY = 0;\n"
    "var HistoryViewMouseX = -1;\n"
    "var HistoryViewMouseY = -1;\n"
    "var MouseHistory = 0;\n"
    "var MouseDetailed = 0;\n"
    "var FontHeight = 10;\n"
    "var FontWidth = 1;\n"
    "var FontAscent = 3; //Set manually\n"
    "var Font = \'Bold \' + FontHeight + \'px Courier New\';\n"
    "var FontFlash = \'Bold \' + 35 + \'px Courier New\';\n"
    "var BoxHeight = FontHeight + 2;\n"
    "var ThreadsActive = new Object();\n"
    "var ThreadsAllActive = 1;\n"
    "var GroupsActive = new Object();\n"
    "var GroupsAllActive = 1;\n"
    "var nMinWidth = 0.01;//subpixel width\n"
    "var nMinWidthPan = 1.0;//subpixel width when panning\n"
    "var nContextSwitchEnabled = 1;\n"
    "var DisableLod = 0;\n"
    "var DisableMerge = 0;\n"
    "var GroupColors = 0;\n"
    "var nModDown = 0;\n"
    "var g_MSG = \'no\';\n"
    "var nDrawCount = 0;\n"
    "var nBackColors = [\'#474747\', \'#313131\' ];\n"
    "var nBackColorOffset = \'#606060\';\n"
    "var CSwitchColors =[\"#9DD8AF\",\"#D7B6DA\",\"#EAAC76\",\"#DBDA61\",\"#8AD5E1\",\"#8CE48B\",\"#C4D688\",\"#57E5C4\"];//generated by "
    "http://tools.medialab.sciences-po.fr/iwanthue/index.php\n"
    "var CSwitchHeight = 5;\n"
    "var FRAME_HISTORY_COLOR_CPU = \'#ff7f27\';\n"
    "var FRAME_HISTORY_COLOR_GPU = \'#ffffff\';\n"
    "var ZOOM_TIME = 0.5;\n"
    "var AnimationActive = false;\n"
    "var nHoverCSCpu = -1;\n"
    "var nHoverCSCpuNext = -1;\n"
    "var nHoverCSToolTip = null;\n"
    "var nHoverToken = -1;\n"
    "var nHoverFrame = -1;\n"
    "var nHoverTokenIndex = -1;\n"
    "var nHoverTokenLogIndex = -1;\n"
    "var nHoverCounter = 0;\n"
    "var nHoverCounterDelta = 8;\n"
    "var nHoverTokenNext = -1;\n"
    "var nHoverTokenLogIndexNext = -1;\n"
    "var nHoverTokenIndexNext = -1;\n"
    "var nHoverCounter = -1;\n"
    "var nHoverTokenDrawn = -1;\n"
    "var nHideHelp = 0;\n"
    "var fFrameScale = 33.33;\n"
    "var SortColumn = 0;\n"
    "var SortColumnOrderFlip = 0;\n"
    "var SortColumnMouseOver = null;\n"
    "var SortColumnMouseOverNext = null;\n"
    "\n"
    "function RangeInit()\n"
    "{\n"
    "	return {\"Begin\":-1, \"End\":-1, \"YBegin\":-1, \"YEnd\":-1, \"Thread\": -1 , \"Index\": -1};\n"
    "}\n"
    "function RangeValid(Range)\n"
    "{\n"
    "	return Range.Begin < Range.End;\n"
    "}\n"
    "function RangeCopy(Dst, Src)\n"
    "{\n"
    "	Dst.Begin = Src.Begin;\n"
    "	Dst.End = Src.End;\n"
    "	Dst.YBegin = Src.YBegin;\n"
    "	Dst.YEnd = Src.YEnd;\n"
    "	Dst.Thread = Src.Thread;\n"
    "}\n"
    "var RangeCpu = RangeInit();\n"
    "var RangeGpu = RangeInit();\n"
    "var RangeSelect = RangeInit();\n"
    "\n"
    "var RangeCpuNext = RangeInit();\n"
    "var RangeGpuNext = RangeInit();\n"
    "\n"
    "var RangeCpuHistory = RangeInit();\n"
    "var RangeGpuHistory = RangeInit();\n"
    "\n"
    "var fRangeBegin = 0;\n"
    "var fRangeEnd = -1;\n"
    "var fRangeThreadId = -1;\n"
    "var fRangeThreadIdNext = -1;\n"
    "var fRangeBeginNext = 0;\n"
    "var fRangeEndNext = 0;\n"
    "var fRangeBeginGpuNext = 0;\n"
    "var fRangeEndGpuNext = 0;\n"
    "var fRangeBeginHistory = -1;\n"
    "var fRangeEndHistory = -1;\n"
    "var fRangeBeginHistoryGpu = -1;\n"
    "var fRangeEndHistoryGpu = -1;\n"
    "var fRangeBeginSelect = 0;\n"
    "var fRangeEndSelect = -1;\n"
    "var ThreadY;\n"
    "\n"
    "var ModeDetailed = 0;\n"
    "var ModeTimers = 1;\n"
    "var ModeCounters = 2;\n"
    "var Mode = ModeTimers;\n"
    "\n"
    "var DebugDrawQuadCount = 0;\n"
    "var DebugDrawTextCount = 0;\n"
    "var ProfileMode = 0;\n"
    "var ProfileRedraw0 = 0;\n"
    "var ProfileRedraw1 = 0;\n"
    "var ProfileRedraw2 = 0;\n"
    "var ProfileFps = 0;\n"
    "var ProfileFpsAggr = 0;\n"
    "var ProfileFpsCount = 0;\n"
    "var ProfileLastTimeStamp = new Date();\n"
    "\n"
    "var CSwitchCache = {};\n"
    "var CSwitchOnlyThreads = [];\n"
    "var ProfileData = {};\n"
    "var ProfileStackTime = {};\n"
    "var ProfileStackName = {};\n"
    "var Debug = 1;\n"
    "\n"
    "var g_MaxStack = Array();\n"
    "var g_TypeArray;\n"
    "var g_TimeArray;\n"
    "var g_IndexArray;\n"
    "var g_LabelArray;\n"
    "var LodData = new Array();\n"
    "var NumLodSplits = 10;\n"
    "var SplitMin = 100;\n"
    "var SPLIT_LIMIT = 1e20;\n"
    "var DPR = 1;\n"
    "var DetailedRedrawState = {};\n"
    "var OffscreenData;\n"
    "var DetailedFrameCounter = 0;\n"
    "var Invalidate = 0;\n"
    "var GroupOrder = Array();\n"
    "var ThreadOrder = Array();\n"
    "var TimersGroups = 0;\n"
    "var TimersMeta = 1;\n"
    "var MetaLengths = Array();\n"
    "var MetaLengthsAvg = Array();\n"
    "var MetaLengthsMax = Array();\n"
    "\n"
    "var ZoomActive = 0;\n"
    "\n"
    "var StrGroup = \"Group\";\n"
    "var StrThread = \"Thread\";\n"
    "var StrTimer = \"Timer\";\n"
    "var StrAverage = \"Average\";\n"
    "var StrMax = \"Max\";\n"
    "var StrTotal = \"Total\";\n"
    "var StrMin = \"Min\";\n"
    "var StrCallAverage = \"Call Average\";\n"
    "var StrCount = \"Count\";\n"
    "var StrExclAverage = \"Excl Average\";\n"
    "var StrExclMax = \"Excl Max\";\n"
    "\n"
    "\n"
    "function ProfileModeClear()\n"
    "{\n"
    "	if(ProfileMode)\n"
    "	{\n"
    "		ProfileData = new Object();\n"
    "		ProfileStackTime = new Array();\n"
    "		ProfileStackName = new Array();\n"
    "	}\n"
    "}\n"
    "function ProfileEnter(Name)\n"
    "{\n"
    "	if(ProfileMode)\n"
    "	{\n"
    "		ProfileStackTime.push(new Date());\n"
    "		ProfileStackName.push(Name);\n"
    "	}\n"
    "}\n"
    "function ProfileLeave()\n"
    "{\n"
    "	if(ProfileMode)\n"
    "	{\n"
    "		var Time = new Date();\n"
    "		var Delta = Time - ProfileStackTime.pop();\n"
    "		var Name = ProfileStackName.pop();\n"
    "		var Obj = ProfileData[Name];\n"
    "		if(!Obj)\n"
    "		{\n"
    "			Obj = new Object();\n"
    "			Obj.Count = 0;\n"
    "			Obj.Name = Name;\n"
    "			Obj.Time = 0;\n"
    "			ProfileData[Name] = Obj;\n"
    "		}\n"
    "		Obj.Time += Delta;\n"
    "		Obj.Count += 1;\n"
    "	}\n"
    "}\n"
    "\n"
    "function ProfilePlot(s)\n"
    "{\n"
    "	if(ProfileMode)\n"
    "	{\n"
    "		var A = ProfileData.Plot;\n"
    "		if(!A)\n"
    "		{\n"
    "			ProfileData.Plot = Array();\n"
    "			A = ProfileData.Plot;\n"
    "		}\n"
    "		if(A.length<10)\n"
    "		{\n"
    "			A.push(s);\n"
    "		}\n"
    "	}\n"
    "}\n"
    "function ProfileModeDump()\n"
    "{\n"
    "	for(var idx in ProfileData)\n"
    "	{\n"
    "		var Timer = ProfileData[idx];\n"
    "		console.log(Timer.Name + \" \" + Timer.Time + \"ms \" + Timer.Count);\n"
    "	}\n"
    "\n"
    "}\n"
    "function ProfileModeDraw(Canvas)\n"
    "{\n"
    "	if(ProfileMode)\n"
    "	{\n"
    "		var StringArray = [];\n"
    "		for(var idx in ProfileData)\n"
    "		{\n"
    "			if(idx == \"Plot\")\n"
    "				continue;\n"
    "			var Timer = ProfileData[idx];\n"
    "			StringArray.push(Timer.Name);\n"
    "			StringArray.push(Timer.Time + \"ms\");\n"
    "			StringArray.push(\"#\");\n"
    "			StringArray.push(\"\" + Timer.Count);\n"
    "		}\n"
    "		StringArray.push(\"debug\");\n"
    "		StringArray.push(Debug);\n"
    "		var Time = new Date();\n"
    "		var Delta = Time - ProfileLastTimeStamp;\n"
    "		ProfileLastTimeStamp = Time;\n"
    "		StringArray.push(\"Frame Delta\");\n"
    "		StringArray.push(Delta + \"ms\");\n"
    "		if(ProfileMode == 2)\n"
    "		{\n"
    "			ProfileFpsAggr += Delta;\n"
    "			ProfileFpsCount ++ ;\n"
    "			var AggrFrames = 10;\n"
    "			if(ProfileFpsCount == AggrFrames)\n"
    "			{\n"
    "				ProfileFps = 1000 / (ProfileFpsAggr / AggrFrames);\n"
    "				ProfileFpsAggr = 0;\n"
    "				ProfileFpsCount = 0;\n"
    "			}\n"
    "			StringArray.push(\"FPS\");\n"
    "			StringArray.push(\"\" + ProfileFps.toFixed(2));\n"
    "		}\n"
    "		StringArray.push(\"ProfileRedraw0\");\n"
    "		StringArray.push(\"\" + ProfileRedraw0);\n"
    "		StringArray.push(\"ProfileRedraw1\");\n"
    "		StringArray.push(\"\" + ProfileRedraw1);\n"
    "		StringArray.push(\"ProfileRedraw2\");\n"
    "		StringArray.push(\"\" + ProfileRedraw2);\n"
    "		ProfileRedraw0 = 0;\n"
    "		ProfileRedraw1 = 0;\n"
    "		ProfileRedraw2 = 0;\n"
    "\n"
    "\n"
    "		for(var i = 0; i < ProfileData.Plot; ++i)\n"
    "		{\n"
    "			StringArray.push(\"\");\n"
    "			StringArray.push(ProfileData.Plot[i]);\n"
    "		}\n"
    "		ProfileData.Plot = Array();\n"
    "		DrawToolTip(StringArray, Canvas, 0, 200);\n"
    "	}\n"
    "}\n"
    "\n"
    "function ToggleDebugMode()\n"
    "{\n"
    "	ProfileMode = (ProfileMode+1)%4;\n"
    "	console.log(\'Toggle Debug Mode \' + ProfileMode);\n"
    "}\n"
    "\n"
    "function DetailedTotal()\n"
    "{\n"
    "	var Total = 0;\n"
    "	for(var i = 0; i < Frames.length; i++)\n"
    "	{\n"
    "		var frfr = Frames[i];\n"
    "		Total += frfr.frameend - frfr.framestart;\n"
    "	}\n"
    "	return Total;\n"
    "}\n"
    "\n"
    "function InitFrameInfo()\n"
    "{\n"
    "\n"
    "	var div = document.getElementById(\'divFrameInfo\');\n"
    "	var txt = \'\';\n"
    "	txt = txt + \'Timers View\' + \'<br>\';\n"
    "	txt = txt + \'Frames:\' + AggregateInfo.Frames +\'<br>\';\n"
    "	txt = txt + \'Time:\' + AggregateInfo.Time.toFixed(2) +\'ms<br>\';\n"
    "	txt = txt + \'<hr>\';\n"
    "	txt = txt + \'Detailed View\' + \'<br>\';\n"
    "	txt = txt + \'Frames:\' + Frames.length +\'<br>\';\n"
    "	txt = txt + \'Time:\' + DetailedTotal().toFixed(2) +\'ms<br>\';\n"
    "	txt = txt + \'<hr>\';\n"
    "	txt = txt + \'Gpu: \' + GpuName+ \'<br>\';\n"
    "	txt = txt + \'Vendor ID: \' + VendorID + \'<br>\';\n"
    "	txt = txt + \'Model ID: \' + ModelID + \'<br>\';\n"
    "	div.innerHTML = txt;\n"
    "}\n"
    "function InitGroups()\n"
    "{\n"
    "	for(groupid in GroupInfo)\n"
    "	{\n"
    "		var TimerArray = Array();\n"
    "		for(timerid in TimerInfo)\n"
    "		{\n"
    "			if(TimerInfo[timerid].group == groupid)\n"
    "			{\n"
    "				TimerArray.push(timerid);\n"
    "			}\n"
    "		}\n"
    "		GroupInfo[groupid].TimerArray = TimerArray;\n"
    "	}\n"
    "}\n"
    "\n"
    "function InitThreadMenu()\n"
    "{\n"
    "	var ulThreadMenu = document.getElementById(\'ThreadSubMenu\');\n"
    "	var MaxLen = 7;\n"
    "	ThreadOrder = CreateOrderArray(ThreadNames, function(a){return a;});\n"
    "	for(var idx in ThreadOrder)\n"
    "	{\n"
    "		var name = ThreadNames[ThreadOrder[idx]];\n"
    "		var li = document.createElement(\'li\');\n"
    "		if(name.length > MaxLen)\n"
    "		{\n"
    "			MaxLen = name.length;\n"
    "		}\n"
    "		li.innerText = name;\n"
    "		var asText = li.innerHTML;\n"
    "		var html = \'<a href=\"javascript:void(0)\" onclick=\"ToggleThread(\\'\' + name + \'\\');\">\' + asText + \'</a>\';\n"
    "		li.innerHTML = html;\n"
    "		ulThreadMenu.appendChild(li);\n"
    "	}\n"
    "	var LenStr = (5+(1+MaxLen) * (1+FontWidth)) + \'px\';\n"
    "	var Lis = ulThreadMenu.getElementsByTagName(\'li\');\n"
    "	for(var i = 0; i < Lis.length; ++i)\n"
    "	{\n"
    "		Lis[i].style[\'width\'] = LenStr;\n"
    "	}\n"
    "}\n"
    "\n"
    "function UpdateThreadMenu()\n"
    "{\n"
    "	var ulThreadMenu = document.getElementById(\'ThreadSubMenu\');\n"
    "	var as = ulThreadMenu.getElementsByTagName(\'a\');\n"
    "	for(var i = 0; i < as.length; ++i)\n"
    "	{\n"
    "		var elem = as[i];\n"
    "		var inner = elem.innerText;\n"
    "		var bActive = false;\n"
    "		if(i < 2)\n"
    "		{\n"
    "			if(inner == \'All\')\n"
    "			{\n"
    "				bActive = ThreadsAllActive;\n"
    "			}\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			bActive = ThreadsActive[inner];\n"
    "		}\n"
    "		if(bActive)\n"
    "		{\n"
    "			elem.style[\'text-decoration\'] = \'underline\';\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			elem.style[\'text-decoration\'] = \'none\';\n"
    "		}\n"
    "	}\n"
    "}\n"
    "\n"
    "function ToggleThread(ThreadName)\n"
    "{\n"
    "	if(ThreadName)\n"
    "	{\n"
    "		if(ThreadsActive[ThreadName])\n"
    "		{\n"
    "			ThreadsActive[ThreadName] = false;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			ThreadsActive[ThreadName] = true;\n"
    "		}\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		if(ThreadsAllActive)\n"
    "		{\n"
    "			ThreadsAllActive = 0;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			ThreadsAllActive = 1;\n"
    "		}\n"
    "	}\n"
    "	Invalidate = 0;\n"
    "	UpdateThreadMenu();\n"
    "	WriteCookie();\n"
    "	Draw(1);\n"
    "\n"
    "}\n"
    "\n"
    "function CreateOrderArray(Source, NameFunc)\n"
    "{\n"
    "	var Temp = Array(Source.length);\n"
    "	for(var i = 0; i < Source.length; ++i)\n"
    "	{\n"
    "		Temp[i] = {};\n"
    "		Temp[i].index = i;\n"
    "		Temp[i].namezz = NameFunc(Source[i]).toLowerCase();\n"
    "	}\n"
    "	Temp.sort(function(l, r)\n"
    "	{ \n"
    "		if(r.namezz<l.namezz)\n"
    "			{return 1;}\n"
    "		if(l.namezz<r.namezz)\n"
    "			{return -1;} \n"
    "		return 0;\n"
    "	} );\n"
    "	var OrderArray = Array(Source.length);\n"
    "	for(var i = 0; i < Source.length; ++i)\n"
    "	{\n"
    "		OrderArray[i] = Temp[i].index;\n"
    "	}\n"
    "	return OrderArray;\n"
    "}\n"
    "\n"
    "\n"
    "function InitGroupMenu()\n"
    "{\n"
    "	var ulGroupMenu = document.getElementById(\'GroupSubMenu\');\n"
    "	var MaxLen = 7;\n"
    "	var MenuArray = Array();\n"
    "	for(var i = 0; i < GroupInfo.length; ++i)\n"
    "	{\n"
    "		var x = {};\n"
    "		x.IsCategory = 0;\n"
    "		x.category = GroupInfo[i].category;\n"
    "		x.name = GroupInfo[i].name;\n"
    "		x.index = i;\n"
    "		MenuArray.push(x);\n"
    "	}\n"
    "	for(var i = 0; i < CategoryInfo.length; ++i)\n"
    "	{\n"
    "		var x = {};\n"
    "		x.IsCategory = 1;\n"
    "		x.category = i;\n"
    "		x.name = CategoryInfo[i];\n"
    "		x.index = i;\n"
    "		MenuArray.push(x);\n"
    "	}\n"
    "	var OrderFunction = function(a){ return a.category + \"__\" + a.name; };\n"
    "	var OrderFunctionMenu = function(a){ return a.IsCategory ? (a.category + \'\') : (a.category + \"__\" + a.name); };\n"
    "	GroupOrder = CreateOrderArray(GroupInfo, OrderFunction);\n"
    "	var MenuOrder = CreateOrderArray(MenuArray, OrderFunctionMenu);\n"
    "\n"
    "	for(var idx in MenuOrder)\n"
    "	{\n"
    "		var MenuItem = MenuArray[MenuOrder[idx]];\n"
    "		var name = MenuItem.name;\n"
    "		var li = document.createElement(\'li\');\n"
    "		if(name.length > MaxLen)\n"
    "		{\n"
    "			MaxLen = name.length;\n"
    "		}\n"
    "		var jsfunc = \'\';\n"
    "		if(MenuItem.IsCategory)\n"
    "		{				\n"
    "			li.innerText = \'[\' + name + \']\';\n"
    "			jsfunc = \"ToggleCategory\";\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			li.innerText = name;\n"
    "			jsfunc = \"ToggleGroup\";\n"
    "		}\n"
    "		var asText = li.innerHTML;\n"
    "		var html = \'<a href=\"javascript:void(0)\" onclick=\"\' + jsfunc + \'(\\'\' + name + \'\\');\">\' + asText + \'</a>\';\n"
    "		li.innerHTML = html;\n"
    "		ulGroupMenu.appendChild(li);\n"
    "	}\n"
    "	var LenStr = (5+(1+MaxLen) * FontWidth) + \'px\';\n"
    "	var Lis = ulGroupMenu.getElementsByTagName(\'li\');\n"
    "	for(var i = 0; i < Lis.length; ++i)\n"
    "	{\n"
    "		Lis[i].style[\'width\'] = LenStr;\n"
    "	}\n"
    "	UpdateGroupMenu();\n"
    "}\n"
    "\n"
    "function UpdateGroupMenu()\n"
    "{\n"
    "	var ulThreadMenu = document.getElementById(\'GroupSubMenu\');\n"
    "	var as = ulThreadMenu.getElementsByTagName(\'a\');\n"
    "	for(var i = 0; i < as.length; ++i)\n"
    "	{\n"
    "		var elem = as[i];\n"
    "		var inner = elem.innerText;\n"
    "		var bActive = false;\n"
    "		if(i < 2)\n"
    "		{\n"
    "			if(inner == \'All\')\n"
    "			{\n"
    "				bActive = GroupsAllActive;\n"
    "			}\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			var CategoryString = inner.length>2 ? inner.substring(1, inner.length-2) : \"\";\n"
    "			var CategoryIdx = CategoryIndex(CategoryString);\n"
    "			if(inner[0] == \'[\' && inner[inner.length-1] == \']\' && CategoryIdx >= 0)\n"
    "			{\n"
    "				bActive = IsCategoryActive(CategoryIdx);\n"
    "			}\n"
    "			else\n"
    "			{\n"
    "				bActive = GroupsActive[inner];\n"
    "			}\n"
    "		}\n"
    "		if(bActive)\n"
    "		{\n"
    "			elem.style[\'text-decoration\'] = \'underline\';\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			elem.style[\'text-decoration\'] = \'none\';\n"
    "		}\n"
    "	}\n"
    "}\n"
    "function CategoryIndex(CategoryName)\n"
    "{\n"
    "	for(var i = 0; i < CategoryInfo.length; ++i)\n"
    "	{\n"
    "		if(CategoryInfo[i] == CategoryName)\n"
    "		{\n"
    "			return i;\n"
    "		}\n"
    "	}\n"
    "	return -1;\n"
    "}\n"
    "function IsCategoryActive(CategoryIdx)\n"
    "{\n"
    "	for(var i = 0; i < GroupInfo.length; ++i)\n"
    "	{\n"
    "		if(GroupInfo[i].category == CategoryIdx)\n"
    "		{\n"
    "			var Name = GroupInfo[i].name;\n"
    "			if(!GroupsActive[Name])\n"
    "			{\n"
    "				return false;\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "	return true;\n"
    "\n"
    "}\n"
    "function ToggleCategory(CategoryName)\n"
    "{\n"
    "	var CategoryIdx = CategoryIndex(CategoryName);\n"
    "	if(CategoryIdx < 0)\n"
    "		return;\n"
    "	var CategoryActive = IsCategoryActive(CategoryIdx);\n"
    "	for(var i = 0; i < GroupInfo.length; ++i)\n"
    "	{\n"
    "		if(GroupInfo[i].category == CategoryIdx)\n"
    "		{\n"
    "			var Name = GroupInfo[i].name;\n"
    "			if(CategoryActive)\n"
    "			{\n"
    "				GroupsActive[Name] = false;\n"
    "			}\n"
    "			else\n"
    "			{\n"
    "				GroupsActive[Name] = true;\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "	UpdateGroupMenu();\n"
    "	WriteCookie();\n"
    "	RequestRedraw();\n"
    "}\n"
    "\n"
    "function ToggleGroup(GroupName)\n"
    "{\n"
    "	if(GroupName)\n"
    "	{\n"
    "		if(GroupsActive[GroupName])\n"
    "		{\n"
    "			GroupsActive[GroupName] = false;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			GroupsActive[GroupName] = true;\n"
    "		}\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		if(GroupsAllActive)\n"
    "		{\n"
    "			GroupsAllActive = 0;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			GroupsAllActive = 1;\n"
    "		}\n"
    "	}\n"
    "	UpdateGroupMenu();\n"
    "	WriteCookie();\n"
    "	RequestRedraw();\n"
    "}\n"
    "function UpdateGroupColors()\n"
    "{\n"
    "	for(var i = 0; i < TimerInfo.length; ++i)\n"
    "	{\n"
    "		if(GroupColors)\n"
    "		{\n"
    "			TimerInfo[i].color = GroupInfo[TimerInfo[i].group].color;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			TimerInfo[i].color = TimerInfo[i].timercolor;\n"
    "		}\n"
    "		TimerInfo[i].textcolorindex = InvertColorIndex(TimerInfo[i].color);\n"
    "	}\n"
    "}\n"
    "\n"
    "function ToggleGroupColors()\n"
    "{\n"
    "	GroupColors = !GroupColors;\n"
    "	UpdateGroupColors();\n"
    "	UpdateOptionsMenu();\n"
    "	WriteCookie();\n"
    "	RequestRedraw();\n"
    "}\n"
    "\n"
    "function UpdateOptionsMenu()\n"
    "{\n"
    "	var ulTimersMeta = document.getElementById(\'TimersMeta\');\n"
    "	ulTimersMeta.style[\'text-decoration\'] = TimersMeta ? \'underline\' : \'none\';\n"
    "	var ulGroupColors = document.getElementById(\'GroupColors\');\n"
    "	ulGroupColors.style[\'text-decoration\'] = GroupColors ? \'underline\' : \'none\';\n"
    "}\n"
    "\n"
    "function ToggleTimersMeta()\n"
    "{\n"
    "	TimersMeta = TimersMeta ? 0 : 1;\n"
    "	WriteCookie();\n"
    "	UpdateOptionsMenu();\n"
    "	RequestRedraw();\n"
    "}\n"
    "\n"
    "function ShowHelp(Show, Forever)\n"
    "{\n"
    "	var HelpWindow = document.getElementById(\'helpwindow\');\n"
    "	if(Show)\n"
    "	{\n"
    "		HelpWindow.style[\'display\'] = \'block\';\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		HelpWindow.style[\'display\'] = \'none\';\n"
    "	}\n"
    "	if(Forever)\n"
    "	{\n"
    "		nHideHelp = Show ? 0 : 1;\n"
    "		WriteCookie();\n"
    "	}\n"
    "}\n"
    "function SetMode(NewMode, Groups)\n"
    "{\n"
    "	var buttonTimers = document.getElementById(\'buttonTimers\');\n"
    "	var buttonDetailed = document.getElementById(\'buttonDetailed\');\n"
    "	var buttonGroups = document.getElementById(\'buttonGroups\');\n"
    "	var buttonThreads = document.getElementById(\'buttonThreads\');\n"
    "	var buttonCounters = document.getElementById(\'buttonCounters\');\n"
    "	var ilThreads = document.getElementById(\'ilThreads\');\n"
    "	var ilGroups = document.getElementById(\'ilGroups\');\n"
    "	var ModeElement = null;\n"
    "	buttonTimers.style[\'text-decoration\'] = \'none\';\n"
    "	buttonGroups.style[\'text-decoration\'] = \'none\';\n"
    "	buttonThreads.style[\'text-decoration\'] = \'none\';\n"
    "	buttonDetailed.style[\'text-decoration\'] = \'none\';\n"
    "	buttonCounters.style[\'text-decoration\'] = \'none\';\n"
    "\n"
    "\n"
    "	if(NewMode == \'counters\' || NewMode == ModeCounters)\n"
    "	{\n"
    "		buttonCounters.style[\'text-decoration\'] = \'underline\';\n"
    "		ilThreads.style[\'display\'] = \'none\';\n"
    "		ilGroups.style[\'display\'] = \'none\';\n"
    "		Mode = ModeCounters;\n"
    "		ModeElement = buttonCounters;\n"
    "\n"
    "	}\n"
    "	else if(NewMode == \'timers\' || NewMode == ModeTimers)\n"
    "	{\n"
    "		TimersGroups = Groups;\n"
    "		buttonTimers.style[\'text-decoration\'] = TimersGroups ? \'none\' : \'underline\';\n"
    "		buttonGroups.style[\'text-decoration\'] = TimersGroups == 1 ? \'underline\' : \'none\';\n"
    "		buttonThreads.style[\'text-decoration\'] = TimersGroups == 2 ? \'underline\' : \'none\';\n"
    "		buttonDetailed.style[\'text-decoration\'] = \'none\';\n"
    "		if(TimersGroups == 0)\n"
    "		{\n"
    "			ilThreads.style[\'display\'] = \'none\';\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			ilThreads.style[\'display\'] = \'block\';\n"
    "		}\n"
    "		ilGroups.style[\'display\'] = \'block\';\n"
    "		Mode = ModeTimers;\n"
    "		ModeElement = TimersGroups == 2 ? buttonThreads : TimersGroups == 1 ? buttonGroups : buttonTimers;\n"
    "\n"
    "	}\n"
    "	else if(NewMode == \'detailed\' || NewMode == ModeDetailed)\n"
    "	{\n"
    "		buttonDetailed.style[\'text-decoration\'] = \'underline\';\n"
    "	\n"
    "		ilThreads.style[\'display\'] = \'block\';\n"
    "		ilGroups.style[\'display\'] = \'none\';\n"
    "		Mode = ModeDetailed;\n"
    "		ModeElement = buttonDetailed;\n"
    "	}\n"
    "	var ModeSubMenuText = document.getElementById(\'ModeSubMenuText\');\n"
    "	ModeSubMenuText.innerText = \'Mode[\' + ModeElement.innerText + \']\';\n"
    "\n"
    "	if(Mode == ModeTimers)\n"
    "	{\n"
    "		SetFilterInput(FilterInputGroupString, FilterInputTimerString);\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		ShowFilterInput(0);\n"
    "	}\n"
    "\n"
    "	WriteCookie();\n"
    "	RequestRedraw();\n"
    "\n"
    "}\n"
    "\n"
    "function SetReferenceTime(TimeString)\n"
    "{\n"
    "	ReferenceTime = parseInt(TimeString);\n"
    "	var ReferenceMenu = document.getElementById(\'ReferenceSubMenu\');\n"
    "	var Links = ReferenceMenu.getElementsByTagName(\'a\');\n"
    "	for(var i = 0; i < Links.length; ++i)\n"
    "	{\n"
    "		if(Links[i].innerHTML.match(\'^\' + TimeString))\n"
    "		{\n"
    "			Links[i].style[\'text-decoration\'] = \'underline\';\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			Links[i].style[\'text-decoration\'] = \'none\';\n"
    "		}\n"
    "	}\n"
    "	WriteCookie();\n"
    "	RequestRedraw();\n"
    "\n"
    "}\n"
    "\n"
    "function ToggleContextSwitch()\n"
    "{\n"
    "	SetContextSwitch(nContextSwitchEnabled ? 0 : 1);\n"
    "}\n"
    "function SetContextSwitch(Enabled)\n"
    "{\n"
    "	nContextSwitchEnabled = Enabled ? 1 : 0;\n"
    "	var ReferenceMenu = document.getElementById(\'OptionsMenu\');\n"
    "	var Links = ReferenceMenu.getElementsByTagName(\'a\');\n"
    "	Links[0].style[\'text-decoration\'] = nContextSwitchEnabled ? \'underline\' : \'none\';\n"
    "	WriteCookie();\n"
    "	RequestRedraw();\n"
    "}\n"
    "\n"
    "function ToggleDebug()\n"
    "{\n"
    "	Debug = (Debug + 1) % 2;\n"
    "}\n"
    "\n"
    "function ToggleDisableMerge()\n"
    "{\n"
    "	DisableMerge = DisableMerge ? 0 : 1;\n"
    "	var ReferenceMenu = document.getElementById(\'OptionsMenu\');\n"
    "	var Links = ReferenceMenu.getElementsByTagName(\'a\');\n"
    "	if(DisableMerge)\n"
    "	{\n"
    "		Links[1].style[\'text-decoration\'] = \'underline\';\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		Links[1].style[\'text-decoration\'] = \'none\';\n"
    "	}\n"
    "\n"
    "}\n"
    "\n"
    "function ToggleDisableLod()\n"
    "{\n"
    "	DisableLod = DisableLod ? 0 : 1;\n"
    "	var ReferenceMenu = document.getElementById(\'OptionsMenu\');\n"
    "	var Links = ReferenceMenu.getElementsByTagName(\'a\');\n"
    "	if(DisableLod)\n"
    "	{\n"
    "		Links[2].style[\'text-decoration\'] = \'underline\';\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		Links[2].style[\'text-decoration\'] = \'none\';\n"
    "	}\n"
    "\n"
    "}\n"
    "\n"
    "function GatherHoverMetaCounters(TimerIndex, StartIndex, nLog, nFrameLast)\n"
    "{\n"
    "	var HoverInfo = new Object();\n"
    "	var StackPos = 1;\n"
    "	//search backwards, count meta counters \n"
    "	for(var i = nFrameLast; i >= 0; i--)\n"
    "	{\n"
    "		var fr = Frames[i];\n"
    "		var ts = fr.ts[nLog];\n"
    "		var ti = fr.ti[nLog];\n"
    "		var tt = fr.tt[nLog];\n"
    "		var start = i == nFrameLast ? StartIndex-1 : ts.length-1;\n"
    "\n"
    "		for(var j = start; j >= 0; j--)\n"
    "		{\n"
    "			var type = tt[j];\n"
    "			var index = ti[j];\n"
    "			var time = ts[j];\n"
    "			if(type == 1)\n"
    "			{\n"
    "				StackPos--;\n"
    "				if(StackPos == 0 && index == TimerIndex)\n"
    "				{\n"
    "					return HoverInfo;\n"
    "				}\n"
    "			}\n"
    "			else if(type == 0)\n"
    "			{\n"
    "				StackPos++;\n"
    "			}\n"
    "			else if(type >= 8)\n"
    "			{\n"
    "				var nMetaCount = type - 8;\n"
    "				var nMetaIndex = MetaNames[index];\n"
    "				if(nMetaIndex in HoverInfo)\n"
    "				{\n"
    "					HoverInfo[nMetaIndex] += nMetaCount;\n"
    "				}\n"
    "				else\n"
    "				{\n"
    "					HoverInfo[nMetaIndex] = nMetaCount;\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "}\n"
    "\n"
    "function GatherHoverLabels(TimerIndex, StartIndex, nLog, nFrameLast)\n"
    "{\n"
    "	var HoverInfo = [];\n"
    "	var StackPos = 1;\n"
    "	//search backwards, aggregate labels\n"
    "	for(var i = nFrameLast; i >= 0; i--)\n"
    "	{\n"
    "		var fr = Frames[i];\n"
    "		var ts = fr.ts[nLog];\n"
    "		var ti = fr.ti[nLog];\n"
    "		var tt = fr.tt[nLog];\n"
    "		var tl = fr.tl[nLog];\n"
    "		var start = i == nFrameLast ? StartIndex-1 : ts.length-1;\n"
    "\n"
    "		for(var j = start; j >= 0; j--)\n"
    "		{\n"
    "			var type = tt[j];\n"
    "			var index = ti[j];\n"
    "			var time = ts[j];\n"
    "			if(type == 1)\n"
    "			{\n"
    "				StackPos--;\n"
    "				if(StackPos == 0 && index == TimerIndex)\n"
    "				{\n"
    "					return HoverInfo.reverse();\n"
    "				}\n"
    "			}\n"
    "			else if(type == 0)\n"
    "			{\n"
    "				StackPos++;\n"
    "			}\n"
    "			else if (type == 3 && StackPos == 1)\n"
    "			{\n"
    "				var Label = tl[index];\n"
    "				HoverInfo.push(Label ? Label : \"??\");\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "}\n"
    "\n"
    "function CalculateTimers(GroupInfo, TimerInfo, nFrameFirst, nFrameLast, nToken, nGroup)\n"
    "{\n"
    "	if(!nFrameFirst || nFrameFirst < 0)\n"
    "		nFrameFirst = 0;\n"
    "	if(!nFrameLast || nFrameLast > Frames.length)\n"
    "		nFrameLast = Frames.length;\n"
    "	var FrameCount = nFrameLast - nFrameFirst;\n"
    "	if(0 == FrameCount)\n"
    "		return;\n"
    "	for(var j = 0; j < GroupInfo.length; j++)\n"
    "	{\n"
    "		GroupInfo[j].Sum = 0;\n"
    "		GroupInfo[j].FrameMax = 0;\n"
    "	}\n"
    "	for(var j = 0; j < TimerInfo.length; j++)\n"
    "	{\n"
    "		TimerInfo[j].CallCount = 0;\n"
    "		TimerInfo[j].Sum = 0;\n"
    "		TimerInfo[j].ExclusiveSum = 0;\n"
    "		TimerInfo[j].Max = 0;\n"
    "		TimerInfo[j].FrameMax = 0;\n"
    "		TimerInfo[j].ExclusiveFrameMax = 0;\n"
    "	}\n"
    "\n"
    "	var nNumLogs = Frames[0].ts.length;\n"
    "	var StackPosArray = Array(nNumLogs);\n"
    "	var StackArray = Array(nNumLogs);\n"
    "	var StackChildArray = Array(nNumLogs);\n"
    "	var GroupPosArray = Array(nNumLogs);\n"
    "	for(var i = 0; i < nNumLogs; ++i)\n"
    "	{\n"
    "		StackPosArray[i] = 0;\n"
    "		StackArray[i] = Array(20);\n"
    "		StackChildArray[i] = Array(20);\n"
    "		GroupPosArray[i] = Array(GroupInfo.length);\n"
    "\n"
    "		var GroupPos = GroupPosArray[i];\n"
    "		for(var j = 0; j < GroupInfo.length; j++)\n"
    "		{\n"
    "			GroupPos[j] = 0;\n"
    "		}\n"
    "	}\n"
    "\n"
    "	for(var i = nFrameFirst; i < nFrameLast; i++)\n"
    "	{\n"
    "		for(var j = 0; j < GroupInfo.length; j++)\n"
    "		{\n"
    "			GroupInfo[j].FrameSum = 0;\n"
    "		}\n"
    "		for(var j = 0; j < TimerInfo.length; j++)\n"
    "		{\n"
    "			TimerInfo[j].FrameSum = 0;\n"
    "			TimerInfo[j].ExclusiveFrameSum = 0;\n"
    "		}\n"
    "\n"
    "		var fr = Frames[i];\n"
    "		for(nLog = 0; nLog < nNumLogs; nLog++)\n"
    "		{\n"
    "			var StackPos = StackPosArray[nLog];\n"
    "			var Stack = StackArray[nLog];\n"
    "			var StackChild = StackChildArray[nLog];\n"
    "			var GroupPos = GroupPosArray[nLog];\n"
    "			var ts = fr.ts[nLog];\n"
    "			var ti = fr.ti[nLog];\n"
    "			var tt = fr.tt[nLog];\n"
    "			var count = ts.length;\n"
    "			for(j = 0; j < count; j++)\n"
    "			{\n"
    "				var type = tt[j];\n"
    "				var index = ti[j];\n"
    "				var time = ts[j];\n"
    "				if(type == 1) //enter\n"
    "				{\n"
    "					//push\n"
    "					Stack[StackPos] = time;\n"
    "					StackPos++;\n"
    "					StackChild[StackPos] = 0;\n"
    "\n"
    "					var groupid = TimerInfo[index].group;\n"
    "					GroupPos[groupid]++;\n"
    "				}\n"
    "				else if(type == 0) // leave\n"
    "				{\n"
    "					var TimeDelta, TimeDeltaExclusive, TimeStart;\n"
    "					if(StackPos>0)\n"
    "					{\n"
    "						StackPos--;\n"
    "						TimeStart = Stack[StackPos];\n"
    "						TimeDelta = time - Stack[StackPos];\n"
    "						TimeDeltaExclusive = TimeDelta - StackChild[StackPos+1];\n"
    "						StackChild[StackPos] += TimeDelta;\n"
    "					}\n"
    "					else\n"
    "					{\n"
    "						TimeStart = Frames[nFrameFirst].framestart;\n"
    "						TimeDelta = time - Frames[nFrameFirst].framestart;\n"
    "						TimeDeltaExclusive = TimeDelta;\n"
    "					}\n"
    "\n"
    "					if(nToken < 0 || nToken == index)\n"
    "					{\n"
    "						TimerInfo[index].CallCount++;\n"
    "						TimerInfo[index].FrameSum += TimeDelta;\n"
    "						TimerInfo[index].ExclusiveFrameSum += TimeDeltaExclusive;\n"
    "						TimerInfo[index].Sum += TimeDelta;\n"
    "						TimerInfo[index].ExclusiveSum += TimeDeltaExclusive;\n"
    "						if(TimeDelta > TimerInfo[index].Max)\n"
    "						{\n"
    "							TimerInfo[index].Max = TimeDelta;\n"
    "							TimerInfo[index].worst = TimeDelta;\n"
    "							TimerInfo[index].worststart = TimeStart;\n"
    "							TimerInfo[index].worstend = time;\n"
    "							TimerInfo[index].worstthread = nLog;\n"
    "						}\n"
    "					}\n"
    "\n"
    "					var groupid = TimerInfo[index].group;\n"
    "					if(nGroup < 0 || nGroup == groupid)\n"
    "					{\n"
    "						if(GroupPos[groupid] > 0)\n"
    "						{\n"
    "							GroupPos[groupid]--;\n"
    "						}\n"
    "						if(GroupPos[groupid] == 0)\n"
    "						{\n"
    "							GroupInfo[groupid].Sum += TimeDelta;\n"
    "							GroupInfo[groupid].FrameSum += TimeDelta;\n"
    "						}\n"
    "					}\n"
    "				}\n"
    "				else\n"
    "				{\n"
    "					//meta\n"
    "				}\n"
    "			}\n"
    "			StackPosArray[nLog] = StackPos;\n"
    "		}\n"
    "		for(var j = 0; j < GroupInfo.length; j++)\n"
    "		{\n"
    "			if(GroupInfo[j].FrameSum > GroupInfo[j].FrameMax)\n"
    "			{\n"
    "				GroupInfo[j].FrameMax = GroupInfo[j].FrameSum;\n"
    "			}\n"
    "		}\n"
    "		for(var j = 0; j < TimerInfo.length; j++)\n"
    "		{\n"
    "			if(TimerInfo[j].FrameSum > TimerInfo[j].FrameMax)\n"
    "			{\n"
    "				TimerInfo[j].FrameMax = TimerInfo[j].FrameSum;\n"
    "			}\n"
    "			if(TimerInfo[j].ExclusiveFrameSum > TimerInfo[j].ExclusiveFrameMax)\n"
    "			{\n"
    "				TimerInfo[j].ExclusiveFrameMax = TimerInfo[j].ExclusiveFrameSum;\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "\n"
    "	for(var j = 0; j < GroupInfo.length; j++)\n"
    "	{\n"
    "		GroupInfo[j].FrameAverage = (GroupInfo[j].Sum / FrameCount);\n"
    "	}\n"
    "	for(var j = 0; j < TimerInfo.length; j++)\n"
    "	{\n"
    "		TimerInfo[j].CallAverage = (TimerInfo[j].Sum / TimerInfo[j].CallCount);\n"
    "		TimerInfo[j].FrameAverage = (TimerInfo[j].Sum / FrameCount);\n"
    "		TimerInfo[j].ExclusiveFrameAverage = (TimerInfo[j].ExclusiveSum / FrameCount);\n"
    "	}\n"
    "}\n"
    "\n"
    "function PreprocessCalculateAllTimers()\n"
    "{\n"
    "	ProfileEnter(\"PreprocessCalculateAllTimers\");\n"
    "	CalculateTimers(GroupInfo, TimerInfo, 0, Frames.length, -1, -1);\n"
    "	ProfileLeave();\n"
    "}\n"
    "\n"
    "var FlashFrames = 10;\n"
    "var FlashFrameCounter = 0;\n"
    "var FlashMessage = \'\';\n"
    "function TimeString(Diff)\n"
    "{\n"
    "	var DiffString = \"0 sec\";\n"
    "	var DiffTable = [1,60,60*60,60*60*24];\n"
    "	var DiffNameTable = [\"sec\", \"min\", \"hr\", \"day\"];\n"
    "	for(var i = 0; i < DiffTable.length; ++i)\n"
    "	{\n"
    "		if(Diff >= DiffTable[i])\n"
    "		{\n"
    "			DiffString = Math.floor(Diff / DiffTable[i]) + \" \" + DiffNameTable[i];\n"
    "		}\n"
    "	}\n"
    "	return DiffString;\n"
    "\n"
    "}\n"
    "function ShowFlashMessage(Message, FrameCount)\n"
    "{\n"
    "	FlashMessage = Message;\n"
    "	FlashFrameCounter = FrameCount;\n"
    "}\n"
    "function OnPageReady()\n"
    "{\n"
    "	var DumpDate = DumpUtcCaptureTime;\n"
    "	var CurrentDate = Date.now() / 1000;\n"
    "	var Diff = CurrentDate - DumpDate;\n"
    "	var Limit = 10*60;//flash old message when loading captures older than 10 minutes \n"
    "	if(Diff > Limit)\n"
    "	{\n"
    "		ShowFlashMessage(\"Captured \" + TimeString(Diff) + \" ago\", 100);\n"
    "	}\n"
    "	if(!nHideHelp)\n"
    "	{\n"
    "		ShowHelp(1,0);\n"
    "	}\n"
    "}\n"
    "\n"
    "function DrawFlashMessage(context)\n"
    "{\n"
    "	if(FlashFrameCounter > 0)\n"
    "	{\n"
    "		if(FlashFrameCounter>1)\n"
    "		{\n"
    "			var FlashPrc = Math.sin(FlashFrameCounter / FlashFrames);\n"
    "			context.font = FontFlash;\n"
    "			context.globalAlpha = FlashPrc * 0.35 + 0.5;\n"
    "			context.textAlign = \'center\';\n"
    "			context.fillStyle = \'red\';\n"
    "			context.fillText(FlashMessage, nWidth * 0.5, 50);\n"
    "			context.globalAlpha = 1;\n"
    "			context.textAlign = \'left\';\n"
    "			context.font = Font;\n"
    "		}\n"
    "		FlashFrameCounter -= 1;\n"
    "\n"
    "	}\n"
    "}\n"
    "\n"
    "function DrawCaptureInfo(context)\n"
    "{\n"
    "	context.fillStyle = \'white\';\n"
    "	context.textAlign = \'right\';\n"
    "	context.font = Font;\n"
    "	var DumpDate = DumpUtcCaptureTime;\n"
    "	var CurrentDate = Date.now() / 1000;\n"
    "	var Diff = CurrentDate - DumpDate;\n"
    "	var DiffString = TimeString(Diff) + \" ago\";\n"
    "	context.fillText(new Date(DumpDate*1000).toLocaleString(), nWidth, FontHeight);\n"
    "	if(Mode == ModeTimers)\n"
    "	{\n"
    "		context.fillText(\"Timer Frames: \" + AggregateInfo.Frames, nWidth, FontHeight*2);\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		context.fillText(\"Detailed Frames \"+ Frames.length, nWidth, FontHeight*2);\n"
    "	}\n"
    "	context.fillText(DumpHost, nWidth, FontHeight*3);\n"
    "	context.fillText(DiffString, nWidth, FontHeight*4);\n"
    "	context.textAlign = \'left\';\n"
    "	DrawFlashMessage(context);\n"
    "}\n"
    "\n"
    "function DrawDetailedFrameHistory()\n"
    "{\n"
    "	ProfileEnter(\"DrawDetailedFrameHistory\");\n"
    "	var x = HistoryViewMouseX;\n"
    "\n"
    "	var context = CanvasHistory.getContext(\'2d\');\n"
    "	context.clearRect(0, 0, CanvasHistory.width, CanvasHistory.height);\n"
    "\n"
    "	var fHeight = nHistoryHeight;\n"
    "	var fWidth = nWidth / Frames.length;\n"
    "	var fHeightScale = fHeight / ReferenceTime;\n"
    "	var fX = 0;\n"
    "	var FrameIndex = -1;\n"
    "	var MouseDragging = MouseDragState != MouseDragOff;\n"
    "	RangeCpuHistory = RangeInit();\n"
    "	RangeGpuHistory = RangeInit()\n"
    "\n"
    "	var FrameFirst = -1;\n"
    "	var FrameLast = nWidth;\n"
    "	var fDetailedOffsetEnd = fDetailedOffset + fDetailedRange;\n"
    "	for(i = 0; i < Frames.length; i++)\n"
    "	{\n"
    "		var fMs = Frames[i].frameend - Frames[i].framestart;\n"
    "		if(fDetailedOffset <= Frames[i].frameend && fDetailedOffset >= Frames[i].framestart)\n"
    "		{\n"
    "			var lerp = (fDetailedOffset - Frames[i].framestart) / (Frames[i].frameend - Frames[i].framestart);\n"
    "			FrameFirst = fX + fWidth * lerp;\n"
    "		}\n"
    "		if(fDetailedOffsetEnd <= Frames[i].frameend && fDetailedOffsetEnd >= Frames[i].framestart)\n"
    "		{\n"
    "			var lerp = (fDetailedOffsetEnd - Frames[i].framestart) / (Frames[i].frameend - Frames[i].framestart);\n"
    "			FrameLast = fX + fWidth * lerp;\n"
    "		}\n"
    "		var fH = fHeightScale * fMs;\n"
    "		var bMouse = x > fX && x < fX + fWidth;\n"
    "		if(bMouse && !MouseDragging)\n"
    "		{\n"
    "			context.fillStyle = FRAME_HISTORY_COLOR_GPU;\n"
    "			RangeCpuHistory.Begin = Frames[i].framestart;\n"
    "			RangeCpuHistory.End = Frames[i].frameend;\n"
    "			if(Frames[i].framestartgpu)\n"
    "			{\n"
    "				RangeGpuHistory.Begin = Frames[i].framestartgpu;\n"
    "				RangeGpuHistory.End = Frames[i].frameendgpu;\n"
    "			}\n"
    "			FrameIndex = i;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			context.fillStyle = FRAME_HISTORY_COLOR_CPU;\n"
    "		}\n"
    "		context.fillRect(fX, fHeight - fH, fWidth-1, fH);\n"
    "		fX += fWidth;\n"
    "	}\n"
    "\n"
    "	var fRangeHistoryBegin = FrameFirst;\n"
    "	var fRangeHistoryEnd = FrameLast;\n"
    "	var X = fRangeHistoryBegin;\n"
    "	var Y = 0;\n"
    "	var W = fRangeHistoryEnd - fRangeHistoryBegin;\n"
    "	context.globalAlpha = 0.35;\n"
    "	context.fillStyle = \'#009900\';\n"
    "	context.fillRect(X, Y, W, fHeight);\n"
    "	context.globalAlpha = 1;\n"
    "	context.strokeStyle = \'#00ff00\';\n"
    "	context.beginPath();\n"
    "	context.moveTo(X, Y);\n"
    "	context.lineTo(X, Y+fHeight);\n"
    "	context.moveTo(X+W, Y);\n"
    "	context.lineTo(X+W, Y+fHeight);\n"
    "	context.stroke();\n"
    "\n"
    "\n"
    "\n"
    "\n"
    "	DrawCaptureInfo(context);\n"
    "\n"
    "	if(FrameIndex>=0 && !MouseDragging)\n"
    "	{\n"
    "		var StringArray = [];\n"
    "		StringArray.push(\"Frame\");\n"
    "		StringArray.push(\"\" + FrameIndex);\n"
    "		StringArray.push(\"Time\");\n"
    "		StringArray.push(\"\" + (Frames[FrameIndex].frameend - Frames[FrameIndex].framestart).toFixed(3));\n"
    "\n"
    "		DrawToolTip(StringArray, CanvasHistory, HistoryViewMouseX, HistoryViewMouseY+20);\n"
    "\n"
    "	}\n"
    "	ProfileLeave();\n"
    "}\n"
    "function TimeToMsString(Time)\n"
    "{\n"
    "	return Time.toFixed(3) + \"ms\";\n"
    "}\n"
    "function TimeToString(Time)\n"
    "{\n"
    "	if(Time > 1000)\n"
    "	{\n"
    "		return (Time/1000.0).toFixed(0) +\"s\";\n"
    "	}\n"
    "	else if(Time > 0.9)\n"
    "	{\n"
    "		return Time.toFixed(0) + \"ms\";\n"
    "	}\n"
    "	else if(Time > 0.0009)\n"
    "	{\n"
    "		return (Time*1000).toFixed(0) + \"us\";\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		return (Time*1000000).toFixed(0) + \"ns\";\n"
    "	}\n"
    "}\n"
    "\n"
    "function DrawDetailedBackground(context)\n"
    "{\n"
    "	var fMs = fDetailedRange;\n"
    "	var fMsEnd = fMs + fDetailedOffset;\n"
    "	var fMsToScreen = nWidth / fMs;\n"
    "	var fRate = Math.floor(2*((Math.log(fMs)/Math.log(10))-1))/2;\n"
    "	var fStep = Math.pow(10, fRate);\n"
    "	var fRcpStep = 1.0 / fStep;\n"
    "	var nColorIndex = Math.floor(fDetailedOffset * fRcpStep) % 2;\n"
    "	if(nColorIndex < 0)\n"
    "		nColorIndex = -nColorIndex;\n"
    "	var fStart = Math.floor(fDetailedOffset * fRcpStep) * fStep;\n"
    "	var fHeight = CanvasDetailedView.height;\n"
    "	var fScaleX = nWidth / fDetailedRange; \n"
    "	var HeaderString = TimeToString(fStep);\n"
    "	context.textAlign = \'center\';\n"
    "	for(f = fStart; f < fMsEnd; )\n"
    "	{\n"
    "		var fNext = f + fStep;\n"
    "		var X = (f - fDetailedOffset) * fScaleX;\n"
    "		var W = (fNext-f)*fScaleX;\n"
    "		context.fillStyle = nBackColors[nColorIndex];\n"
    "		context.fillRect(X, 0, W+2, fHeight);\n"
    "		nColorIndex = 1 - nColorIndex;\n"
    "		context.fillStyle = \'#777777\'\n"
    "		context.fillText(HeaderString, X + W * 0.5, 10);\n"
    "		context.fillText(HeaderString, X + W * 0.5, nHeight - 10);\n"
    "		f = fNext;\n"
    "	}\n"
    "	context.textAlign = \'left\';\n"
    "	var fScaleX = nWidth / fDetailedRange; \n"
    "	context.globalAlpha = 0.5;\n"
    "	context.strokeStyle = \'#bbbbbb\';\n"
    "	context.beginPath();\n"
    "	for(var i = 0; i < Frames.length; i++)\n"
    "	{\n"
    "		var frfr = Frames[i];\n"
    "		if(frfr.frameend < fDetailedOffset || frfr.framestart > fDetailedOffset + fDetailedRange)\n"
    "		{\n"
    "			continue;\n"
    "		}\n"
    "		var X = (frfr.framestart - fDetailedOffset) * fScaleX;\n"
    "		if(X >= 0 && X < nWidth)\n"
    "		{\n"
    "			context.moveTo(X, 0);\n"
    "			context.lineTo(X, nHeight);\n"
    "		}\n"
    "	}\n"
    "	context.stroke();\n"
    "	context.globalAlpha = 1;\n"
    "\n"
    "}\n"
    "function DrawToolTip(StringArray, Canvas, x, y, color)\n"
    "{\n"
    "	var context = Canvas.getContext(\'2d\');\n"
    "	context.font = Font;\n"
    "	var WidthArray = Array(StringArray.length);\n"
    "	var nMaxWidth = 0;\n"
    "	var nHeight = 0;\n"
    "	for(i = 0; i < StringArray.length; i += 2)\n"
    "	{\n"
    "		var nWidth0 = context.measureText(StringArray[i]).width;\n"
    "		var nWidth1 = context.measureText(StringArray[i+1]).width;\n"
    "		var nSum = nWidth0 + nWidth1;\n"
    "		WidthArray[i] = nWidth0;\n"
    "		WidthArray[i+1] = nWidth1;\n"
    "		if(nSum > nMaxWidth)\n"
    "		{\n"
    "			nMaxWidth = nSum;\n"
    "		}\n"
    "		nHeight += BoxHeight;\n"
    "	}\n"
    "	nMaxWidth += 15;\n"
    "	//bounds check.\n"
    "	var CanvasRect = Canvas.getBoundingClientRect();\n"
    "	if(y + nHeight > CanvasRect.height)\n"
    "	{\n"
    "		y = CanvasRect.height - nHeight;\n"
    "		x += 20;\n"
    "	}\n"
    "	if(x + nMaxWidth > CanvasRect.width)\n"
    "	{\n"
    "		x = CanvasRect.width - nMaxWidth;\n"
    "	}\n"
    "\n"
    "	context.fillStyle = color ? color : \'black\';\n"
    "	context.fillRect(x-2, y-1, nMaxWidth+4, nHeight+2);\n"
    "	context.fillStyle = \'black\';\n"
    "	context.fillRect(x-1, y, nMaxWidth+2, nHeight);\n"
    "	context.fillStyle = \'white\';\n"
    "\n"
    "	var XPos = x;\n"
    "	var XPosRight = x + nMaxWidth;\n"
    "	var YPos = y + BoxHeight-2;\n"
    "	for(i = 0; i < StringArray.length; i += 2)\n"
    "	{\n"
    "		context.fi";

const size_t g_ProfileHtml_end_0_size = sizeof(g_ProfileHtml_end_0);
const char   g_ProfileHtml_end_1[] =
    "llText(StringArray[i], XPos, YPos);\n"
    "		context.fillText(StringArray[i+1], XPosRight - WidthArray[i+1], YPos);\n"
    "		YPos += BoxHeight;\n"
    "	}\n"
    "}\n"
    "function CloneObject(obj)\n"
    "{\n"
    "	var copy = new Object();\n"
    "	for(var attr in obj)\n"
    "	{\n"
    "		if(obj.hasOwnProperty(attr))\n"
    "		{\n"
    "			copy[attr] = obj[attr];\n"
    "		}\n"
    "	}\n"
    "	return copy;\n"
    "}\n"
    "function CloneArray(arr)\n"
    "{\n"
    "	var result = Array(arr.length);\n"
    "	for(var i = 0; i < arr.length; ++i)\n"
    "	{\n"
    "		result[i] = CloneObject(arr[i]);\n"
    "	}\n"
    "	return result;\n"
    "}\n"
    "function DrawHoverToolTip()\n"
    "{\n"
    "	if(!ToolTip)\n"
    "	{\n"
    "		return;\n"
    "	}\n"
    "	ProfileEnter(\"DrawHoverToolTip\");\n"
    "	if(nHoverToken != -1)\n"
    "	{\n"
    "		var StringArray = [];\n"
    "\n"
    "		var Timer = TimerInfo[nHoverToken];\n"
    "		var Group = GroupInfo[Timer.group];\n"
    "\n"
    "		var bShowTimers = Mode == ModeTimers;\n"
    "		if(ToolTip == 2)\n"
    "		{ //0: off, 1: default, 2: flipped\n"
    "			bShowTimers = !bShowTimers;\n"
    "		}\n"
    "		if(bShowTimers || nHoverFrame == -1)\n"
    "		{\n"
    "			StringArray.push(\"Timer:\");\n"
    "			StringArray.push(Timer.name);\n"
    "\n"
    "			StringArray.push(\"\");\n"
    "			StringArray.push(\"\");\n"
    "\n"
    "			StringArray.push(\"Average:\");\n"
    "			StringArray.push(Timer.average.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Max:\");\n"
    "			StringArray.push(Timer.max.toFixed(3)+\"ms\");\n"
    "\n"
    "			StringArray.push(\"\");\n"
    "			StringArray.push(\"\");\n"
    "\n"
    "			StringArray.push(\"Exclusive Average:\");\n"
    "			StringArray.push(Timer.exclaverage.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Exclusive Max:\");\n"
    "			StringArray.push(Timer.exclmax.toFixed(3)+\"ms\");\n"
    "\n"
    "			StringArray.push(\"\");\n"
    "			StringArray.push(\"\");\n"
    "\n"
    "			StringArray.push(\"Call Average:\");\n"
    "			StringArray.push(Timer.callaverage.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Call Count:\");\n"
    "			StringArray.push((Timer.callcount / AggregateInfo.Frames).toFixed(2));\n"
    "\n"
    "			StringArray.push(\"\");\n"
    "			StringArray.push(\"\");\n"
    "\n"
    "			StringArray.push(\"Group:\");\n"
    "			StringArray.push(Group.name);\n"
    "			StringArray.push(\"Frame Average:\");\n"
    "			StringArray.push(Group.average.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Frame Max:\");\n"
    "			StringArray.push(Group.max.toFixed(3)+\"ms\");\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			var FrameGroupInfo = CloneArray(GroupInfo);\n"
    "			var FrameTimerInfo = CloneArray(TimerInfo);\n"
    "\n"
    "			CalculateTimers(FrameGroupInfo, FrameTimerInfo, nHoverFrame, nHoverFrame+1, nHoverToken, Timer.group);\n"
    "\n"
    "			var GroupTime = FrameGroupInfo[Timer.group];\n"
    "			var FrameTime = FrameTimerInfo[nHoverToken];\n"
    "\n"
    "			StringArray.push(\"Timer:\");\n"
    "			StringArray.push(Timer.name);\n"
    "			StringArray.push(\"Time:\");\n"
    "			StringArray.push((Group.isgpu ? RangeGpu.End-RangeGpu.Begin : RangeCpu.End-RangeCpu.Begin).toFixed(3)+\"ms\");\n"
    "\n"
    "			StringArray.push(\"\");\n"
    "			StringArray.push(\"\");\n"
    "\n"
    "			StringArray.push(\"Frame Time:\");\n"
    "			StringArray.push(FrameTime.Sum.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Average:\");\n"
    "			StringArray.push(Timer.FrameAverage.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Max:\");\n"
    "			StringArray.push(Timer.FrameMax.toFixed(3)+\"ms\");\n"
    "\n"
    "			StringArray.push(\"\");\n"
    "			StringArray.push(\"\");\n"
    "\n"
    "			StringArray.push(\"Call Average:\");\n"
    "			StringArray.push(Timer.CallAverage.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Call Count:\");\n"
    "			StringArray.push((Timer.CallCount / Frames.length).toFixed(2));\n"
    "\n"
    "			StringArray.push(\"\");\n"
    "			StringArray.push(\"\");\n"
    "\n"
    "			StringArray.push(\"Exclusive Frame Time:\");\n"
    "			StringArray.push(FrameTime.ExclusiveSum.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Exclusive Average:\");\n"
    "			StringArray.push(Timer.ExclusiveFrameAverage.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Exclusive Max:\");\n"
    "			StringArray.push(Timer.ExclusiveFrameMax.toFixed(3)+\"ms\");\n"
    "\n"
    "			StringArray.push(\"\");\n"
    "			StringArray.push(\"\");\n"
    "\n"
    "			StringArray.push(\"Group:\");\n"
    "			StringArray.push(Group.name);\n"
    "			StringArray.push(\"Frame Time:\");\n"
    "			StringArray.push(GroupTime.Sum.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Frame Average:\");\n"
    "			StringArray.push(Group.FrameAverage.toFixed(3)+\"ms\");\n"
    "			StringArray.push(\"Frame Max:\");\n"
    "			StringArray.push(Group.FrameMax.toFixed(3)+\"ms\");\n"
    "\n"
    "			var HoverMeta = GatherHoverMetaCounters(nHoverToken, nHoverTokenIndex, nHoverTokenLogIndex, nHoverFrame);\n"
    "			var HeaderMeta = 0;\n"
    "			for(index in HoverMeta)\n"
    "			{\n"
    "				if(0 == HeaderMeta)\n"
    "				{\n"
    "					HeaderMeta = 1;\n"
    "					StringArray.push(\"\");\n"
    "					StringArray.push(\"\");\n"
    "				}\n"
    "				StringArray.push(\"\"+index);\n"
    "				StringArray.push(\"\"+HoverMeta[index]);\n"
    "			}\n"
    "\n"
    "			var HoverLabel = GatherHoverLabels(nHoverToken, nHoverTokenIndex, nHoverTokenLogIndex, nHoverFrame);\n"
    "			if(HoverLabel.length > 0)\n"
    "			{\n"
    "				StringArray.push(\"\");\n"
    "				StringArray.push(\"\");\n"
    "\n"
    "				for(index in HoverLabel)\n"
    "				{\n"
    "					StringArray.push(\"Label:\")\n"
    "					StringArray.push(HoverLabel[index]);\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "		DrawToolTip(StringArray, CanvasDetailedView, DetailedViewMouseX, DetailedViewMouseY+20, Timer.color);\n"
    "	}\n"
    "	else if(nHoverCSCpu >= 0)\n"
    "	{\n"
    "		var StringArray = [];\n"
    "		StringArray.push(\"Context Switch\");\n"
    "		StringArray.push(\"\");\n"
    "		StringArray.push(\"\");\n"
    "		StringArray.push(\"\");\n"
    "		StringArray.push(\"Cpu\");\n"
    "		StringArray.push(\"\" + nHoverCSCpu);\n"
    "		StringArray.push(\"Begin\");\n"
    "		StringArray.push(\"\" + RangeCpu.Begin);\n"
    "		StringArray.push(\"End\");\n"
    "		StringArray.push(\"\" + RangeCpu.End);\n"
    "		DrawToolTip(StringArray, CanvasDetailedView, DetailedViewMouseX, DetailedViewMouseY+20);\n"
    "	}\n"
    "	ProfileLeave();\n"
    "}\n"
    "\n"
    "function FormatMeta(Value, Dec)\n"
    "{\n"
    "	if(!Value)\n"
    "	{\n"
    "		Value = \"0\";\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		Value = \'\' + Value.toFixed(Dec);\n"
    "	}\n"
    "	return Value;\n"
    "}\n"
    "\n"
    "function DrawBarView()\n"
    "{\n"
    "	ProfileEnter(\"DrawBarView\");\n"
    "	Invalidate++;\n"
    "	nHoverToken = -1;\n"
    "	nHoverFrame = -1;\n"
    "	var context = CanvasDetailedView.getContext(\'2d\');\n"
    "	context.clearRect(0, 0, nWidth, nHeight);\n"
    "\n"
    "	var Height = BoxHeight;\n"
    "	var Width = nWidth;\n"
    "\n"
    "	//clamp offset to prevent scrolling into the void\n"
    "	var nTotalRows = 0;\n"
    "	for(var groupid in GroupInfo)\n"
    "	{\n"
    "		if(GroupsAllActive || GroupsActive[GroupInfo[groupid].name])\n"
    "		{\n"
    "			nTotalRows += GroupInfo[groupid].TimerArray.length + 1;\n"
    "		}\n"
    "	}\n"
    "	var nTotalRowPixels = nTotalRows * Height;\n"
    "	var nFrameRows = nHeight - BoxHeight;\n"
    "	if(nOffsetBarsY + nFrameRows > nTotalRowPixels && nTotalRowPixels > nFrameRows)\n"
    "	{\n"
    "		nOffsetBarsY = nTotalRowPixels - nFrameRows;\n"
    "	}\n"
    "\n"
    "\n"
    "	var Y = -nOffsetBarsY + BoxHeight;\n"
    "	if(TimersGroups)\n"
    "	{\n"
    "		nOffsetBarsX = 0;\n"
    "	}\n"
    "	var XBase = -nOffsetBarsX;\n"
    "	var nColorIndex = 0;\n"
    "\n"
    "	context.fillStyle = \'white\';\n"
    "	context.font = Font;\n"
    "	var bMouseIn = 0;\n"
    "	var RcpReferenceTime = 1.0 / ReferenceTime;\n"
    "	var CountWidth = 8 * FontWidth;\n"
    "	var nMetaLen = TimerInfo[0].meta.length;\n"
    "	var nMetaCharacters = 10;\n"
    "	var InnerBoxHeight = BoxHeight-2;\n"
    "	var TimerLen = 8; //todo: fix max digits.\n"
    "	var TimerWidth = TimerLen * FontWidth;\n"
    "	var nWidthBars = nBarsWidth+2;\n"
    "	var nWidthMs = TimerWidth+2+10;\n"
    "\n"
    "\n"
    "\n"
    "	for(var i = 0; i < nMetaLen; ++i)\n"
    "	{\n"
    "		if(nMetaCharacters < MetaNames[i].length)\n"
    "			nMetaCharacters = MetaNames[i].length;\n"
    "	}\n"
    "	var nWidthMeta = nMetaCharacters * FontWidth + 6;\n"
    "	function HeaderMouseHandle(XBegin, X, Header)\n"
    "	{\n"
    "		var bMouseIn = DetailedViewMouseY >= 0 && DetailedViewMouseY < BoxHeight && DetailedViewMouseX < X && DetailedViewMouseX > "
    "XBegin;\n"
    "		if(bMouseIn)\n"
    "		{\n"
    "			SortColumnMouseOverNext = Header;\n"
    "		}\n"
    "	}\n"
    "	function HeaderString(Header)\n"
    "	{\n"
    "		if(Header == SortColumnMouseOver)\n"
    "		{\n"
    "			return Header + (SortColumnOrderFlip ? \'<\' : \'>\');\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			return Header;\n"
    "		}\n"
    "\n"
    "	}\n"
    "	function DrawHeaderSplit(Header)\n"
    "	{\n"
    "		context.fillStyle = \'white\';\n"
    "		context.fillText(HeaderString(Header), X, Height-FontAscent);\n"
    "		var XBegin = X;\n"
    "		X += nWidthBars;\n"
    "		context.fillStyle = nBackColorOffset;\n"
    "		X += nWidthMs;\n"
    "\n"
    "		if(X >= NameWidth)\n"
    "		{\n"
    "			context.fillRect(X-3, 0, 1, nHeight);\n"
    "		}\n"
    "\n"
    "		HeaderMouseHandle(XBegin, X, Header);\n"
    "	}\n"
    "	function DrawHeaderSplitSingle(Header, Width)\n"
    "	{\n"
    "		context.fillStyle = \'white\';\n"
    "		context.fillText(HeaderString(Header), X, Height-FontAscent);\n"
    "		var XBegin = X;\n"
    "		X += Width;\n"
    "		context.fillStyle = nBackColorOffset;\n"
    "		if(X >= NameWidth)\n"
    "		{\n"
    "			context.fillRect(X-3, 0, 1, nHeight);\n"
    "		}\n"
    "		HeaderMouseHandle(XBegin, X, Header);\n"
    "	}\n"
    "	function DrawHeaderSplitLeftRight(HeaderLeft, HeaderRight, Width)\n"
    "	{\n"
    "		context.textAlign = \'left\';\n"
    "		context.fillStyle = \'white\';\n"
    "		context.fillText(HeaderLeft, X, Height-FontAscent);\n"
    "		var XBegin = X;\n"
    "		X += Width;\n"
    "		context.textAlign = \'right\';\n"
    "		context.fillText(HeaderRight, X-5, Height-FontAscent);\n"
    "		context.textAlign = \'left\';\n"
    "		context.fillStyle = nBackColorOffset;\n"
    "		if(X >= NameWidth)\n"
    "		{\n"
    "			context.fillRect(X-3, 0, 1, nHeight);\n"
    "		}\n"
    "		HeaderMouseHandle(XBegin, X, HeaderLeft);\n"
    "	}\n"
    "	function DrawTimer(Value, Color)\n"
    "	{\n"
    "		var Prc = Value * RcpReferenceTime;\n"
    "		var YText = Y+Height-FontAscent;\n"
    "		if(Prc > 1)\n"
    "		{\n"
    "			Prc = 1;\n"
    "		}\n"
    "		context.fillStyle = Color;\n"
    "		context.fillRect(X+1, Y+1, Prc * nBarsWidth, InnerBoxHeight);\n"
    "		X += nWidthBars;\n"
    "		context.fillStyle = \'white\';\n"
    "		context.fillText((\"      \" + Value.toFixed(2)).slice(-TimerLen), X, YText);\n"
    "		X += nWidthMs;\n"
    "	}\n"
    "	function DrawMeta(Value, Width, Dec, YText)\n"
    "	{\n"
    "		Value = FormatMeta(Value, Dec);\n"
    "		X += (FontWidth*Width);\n"
    "		context.textAlign = \'right\';\n"
    "		context.fillText(Value, X-FontWidth, YText);\n"
    "		context.textAlign = \'left\';\n"
    "	}\n"
    "\n"
    "\n"
    "\n"
    "	function DrawTimerRow(timerid, showgroup)\n"
    "	{\n"
    "		var Timer = TimerInfo[timerid];\n"
    "		var Average = Timer.average;\n"
    "		var Max = Timer.max;\n"
    "		var Min = Timer.min;\n"
    "		var ExclusiveMax = Timer.exclmax;\n"
    "		var ExclusiveAverage = Timer.exclaverage;\n"
    "		var CallAverage = Timer.callaverage;\n"
    "		var CallCount = Timer.callcount;\n"
    "		var YText = Y+Height-FontAscent;\n"
    "		X = NameWidth + XBase;\n"
    "\n"
    "		nColorIndex = 1-nColorIndex;\n"
    "		bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;\n"
    "		if(bMouseIn)\n"
    "		{\n"
    "			nHoverToken = timerid;\n"
    "		}\n"
    "		context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];\n"
    "		context.fillRect(0, Y, Width, FontHeight+2);\n"
    "\n"
    "		DrawTimer(Average, Timer.color);\n"
    "		DrawTimer(Max,Timer.color);\n"
    "		DrawTimer(Timer.total,Timer.color);\n"
    "		DrawTimer(Min,Timer.color);\n"
    "		DrawTimer(CallAverage,Timer.color);\n"
    "		context.fillStyle = \'white\';\n"
    "		context.fillText(CallCount, X, YText);\n"
    "		X += CountWidth;\n"
    "		DrawTimer(ExclusiveAverage,Timer.color);\n"
    "		DrawTimer(ExclusiveMax,Timer.color);\n"
    "\n"
    "		if(TimersMeta)\n"
    "		{\n"
    "			context.fillStyle = \'white\';\n"
    "			for(var j = 0; j < nMetaLen; ++j)\n"
    "			{\n"
    "				DrawMeta(Timer.meta[j], MetaLengths[j], 0, YText);\n"
    "				DrawMeta(Timer.metaagg[j]/AggregateInfo.Frames, MetaLengthsAvg[j], 2, YText);\n"
    "				DrawMeta(Timer.metamax[j], MetaLengthsMax[j], 0, YText);\n"
    "			}\n"
    "		}\n"
    "		context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];\n"
    "		context.fillRect(0, Y, NameWidth, Height);\n"
    "		context.textAlign = \'right\';\n"
    "		context.fillStyle = Timer.color;\n"
    "		context.fillText(Timer.name, NameWidth - 5, YText);\n"
    "		context.textAlign = \'left\';\n"
    "		if(showgroup)\n"
    "		{\n"
    "			context.fillStyle = \'white\';\n"
    "			context.fillText(GroupInfo[Timer.group].name, 1, YText);\n"
    "		}\n"
    "	}\n"
    "	function FilterMatch(FilterArray, value)\n"
    "	{\n"
    "		if(!FilterArray)\n"
    "			return true;\n"
    "		for(var i = 0; i < FilterArray.length; ++i)\n"
    "		{\n"
    "			var res = value.search(FilterArray[i]);\n"
    "			if(res<0)\n"
    "				return false;\n"
    "		}\n"
    "		return true;\n"
    "	}\n"
    "	if(SortColumn)\n"
    "	{\n"
    "		var OrderArray = new Array(TimerInfo.length);\n"
    "		var KeyArray = new Array(TimerInfo.length);\n"
    "		for(var idx in GroupOrder)\n"
    "		{\n"
    "			var Group = GroupInfo[idx];\n"
    "			if((GroupsAllActive || GroupsActive[Group.name]) && FilterMatch(FilterGroup, Group.name))\n"
    "			{\n"
    "				var TimerArray = Group.TimerArray;\n"
    "				for(var timerindex in TimerArray)\n"
    "				{\n"
    "					var timerid = TimerArray[timerindex];\n"
    "					if(FilterMatch(FilterTimer, TimerInfo[timerid].name))\n"
    "					{\n"
    "						OrderArray.push(timerid);\n"
    "					}\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "		var KeyFunc = null;\n"
    "		switch(SortColumn)\n"
    "		{\n"
    "			case 1: KeyFunc = function (a) { return TimerInfo[a].average; }; break;\n"
    "			case 2: KeyFunc = function (a) { return TimerInfo[a].max; }; break;\n"
    "			case 3: KeyFunc = function (a) { return TimerInfo[a].total; }; break;\n"
    "			case 4: KeyFunc = function (a) { return TimerInfo[a].min; }; break;\n"
    "			case 5: KeyFunc = function (a) { return TimerInfo[a].callaverage; }; break;\n"
    "			case 6: KeyFunc = function (a) { return TimerInfo[a].callcount; }; break;\n"
    "			case 7: KeyFunc = function (a) { return TimerInfo[a].exclaverage; }; break;\n"
    "			case 8: KeyFunc = function (a) { return TimerInfo[a].exclmax; }; break;\n"
    "		}\n"
    "\n"
    "		var Flip = SortColumnOrderFlip == 1 ? -1 : 1;\n"
    "		OrderArray.sort(function(a,b) { return Flip * (KeyFunc(b) - KeyFunc(a)); } );\n"
    "\n"
    "		for(var i in OrderArray)\n"
    "		{\n"
    "			DrawTimerRow(OrderArray[i], 1);\n"
    "			Y += Height;\n"
    "		}			\n"
    "\n"
    "	}\n"
    "	else if(2 == TimersGroups)\n"
    "	{\n"
    "		for(var i = 0; i < ThreadNames.length; ++i)\n"
    "		{\n"
    "			if((ThreadsActive[ThreadNames[i]] || ThreadsAllActive) && FilterMatch(FilterTimer, ThreadNames[i]))\n"
    "			{\n"
    "				var X = 0;\n"
    "				var YText = Y+Height-FontAscent;\n"
    "				bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;\n"
    "				nColorIndex = 1-nColorIndex;\n"
    "				context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];\n"
    "				context.fillRect(0, Y, Width, FontHeight+2);\n"
    "				var ThreadColor = CSwitchColors[i % CSwitchColors.length];\n"
    "				context.fillStyle = ThreadColor;\n"
    "				context.fillText(ThreadNames[i], 1, YText);\n"
    "				context.textAlign = \'left\';\n"
    "				Y += Height;\n"
    "				for(var idx in GroupOrder)\n"
    "				{\n"
    "					var groupid = GroupOrder[idx];\n"
    "					var Group = GroupInfo[groupid];\n"
    "					var PerThreadTimerTotal = ThreadGroupTimeArray[i][groupid];\n"
    "					var PerThreadTimer = PerThreadTimerTotal / AggregateInfo.Frames;\n"
    "					if((PerThreadTimer > 0.0001|| PerThreadTimerTotal>0.1) && (GroupsAllActive || GroupsActive[Group.name]) && "
    "FilterMatch(FilterGroup, Group.name))\n"
    "					{\n"
    "						var GColor = GroupColors ? GroupInfo[groupid].color : \'white\';\n"
    "						var X = 0;\n"
    "						nColorIndex = 1-nColorIndex;\n"
    "						bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;\n"
    "						context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];\n"
    "						context.fillRect(0, Y, Width, nHeight);\n"
    "						context.fillStyle = GColor;\n"
    "						context.textAlign = \'right\';\n"
    "						context.fillText(Group.name, NameWidth - 5, Y+Height-FontAscent);\n"
    "						context.textAlign = \'left\';\n"
    "						X += NameWidth;\n"
    "						DrawTimer(PerThreadTimer, GColor);\n"
    "						X += nWidthBars + nWidthMs;	\n"
    "						DrawTimer(PerThreadTimerTotal, GColor);\n"
    "\n"
    "						Y += Height;\n"
    "					}\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		for(var idx in GroupOrder)\n"
    "		{\n"
    "			var groupid = GroupOrder[idx];\n"
    "			var Group = GroupInfo[groupid];\n"
    "			var GColor = GroupColors ? GroupInfo[groupid].color : \'white\';\n"
    "			if((GroupsAllActive || GroupsActive[Group.name]) && FilterMatch(FilterGroup, Group.name))\n"
    "			{\n"
    "				var TimerArray = Group.TimerArray;\n"
    "				var X = XBase;\n"
    "				nColorIndex = 1-nColorIndex;\n"
    "				bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;\n"
    "				context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];\n"
    "				context.fillRect(0, Y, Width, FontHeight+2);\n"
    "				context.fillStyle = GColor;\n"
    "				context.fillText(Group.name, 1, Y+Height-FontAscent);\n"
    "				X += NameWidth;\n"
    "				DrawTimer(Group.average, GColor);\n"
    "				DrawTimer(Group.max, GColor);\n"
    "				DrawTimer(Group.total, GColor);\n"
    "\n"
    "				context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];\n"
    "				context.fillRect(0, Y, NameWidth, FontHeight+2);\n"
    "				context.fillStyle = GColor;\n"
    "				context.fillText(Group.name, 1, Y+Height-FontAscent);\n"
    "\n"
    "\n"
    "\n"
    "				Y += Height;\n"
    "				if(TimersGroups)\n"
    "				{\n"
    "					for(var i = 0; i < ThreadNames.length; ++i)\n"
    "					{\n"
    "						var PerThreadTimerTotal = ThreadGroupTimeArray[i][groupid];\n"
    "						var PerThreadTimer = PerThreadTimerTotal / AggregateInfo.Frames;\n"
    "						if((PerThreadTimer > 0.0001|| PerThreadTimerTotal>0.1) && (ThreadsActive[ThreadNames[i]] || ThreadsAllActive) "
    "&& FilterMatch(FilterTimer, ThreadNames[i]))\n"
    "						{\n"
    "							var YText = Y+Height-FontAscent;\n"
    "							bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + BoxHeight;\n"
    "							nColorIndex = 1-nColorIndex;\n"
    "							context.fillStyle = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];\n"
    "							context.fillRect(0, Y, Width, FontHeight+2);\n"
    "							var ThreadColor = CSwitchColors[i % CSwitchColors.length];\n"
    "							context.fillStyle = ThreadColor;\n"
    "							context.textAlign = \'right\';\n"
    "							context.fillText(ThreadNames[i], NameWidth - 5, YText);\n"
    "							context.textAlign = \'left\';\n"
    "							X = NameWidth;\n"
    "							DrawTimer(PerThreadTimer, ThreadColor);\n"
    "							X += nWidthBars + nWidthMs;	\n"
    "							DrawTimer(PerThreadTimerTotal, ThreadColor);\n"
    "							Y += Height;\n"
    "						}\n"
    "					}\n"
    "				}\n"
    "				else\n"
    "				{\n"
    "					for(var timerindex in TimerArray)\n"
    "					{\n"
    "						var timerid = TimerArray[timerindex];\n"
    "						if(FilterMatch(FilterTimer, TimerInfo[timerid].name))\n"
    "						{\n"
    "							DrawTimerRow(timerid, 0);\n"
    "							Y += Height;\n"
    "						}\n"
    "					}			\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "	X = 0;\n"
    "	context.fillStyle = nBackColorOffset;\n"
    "	context.fillRect(0, 0, Width, Height);\n"
    "	context.fillStyle = \'white\';\n"
    "	SortColumnMouseOverNext = null;\n"
    "\n"
    "	if(TimersGroups)\n"
    "	{\n"
    "		if(2 == TimersGroups)\n"
    "		{\n"
    "			DrawHeaderSplitLeftRight(StrThread, StrGroup, NameWidth);\n"
    "			DrawHeaderSplit(StrAverage);\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			DrawHeaderSplitLeftRight(StrGroup, StrThread, NameWidth);\n"
    "			DrawHeaderSplit(StrAverage);\n"
    "			DrawHeaderSplit(StrMax);\n"
    "			DrawHeaderSplit(StrTotal);\n"
    "		}\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		X = NameWidth + XBase;\n"
    "		DrawHeaderSplit(StrAverage);\n"
    "		DrawHeaderSplit(StrMax);\n"
    "		DrawHeaderSplit(StrTotal);\n"
    "		DrawHeaderSplit(StrMin);\n"
    "		DrawHeaderSplit(StrCallAverage);\n"
    "		DrawHeaderSplitSingle(StrCount, CountWidth);\n"
    "		DrawHeaderSplit(StrExclAverage);\n"
    "		DrawHeaderSplit(StrExclMax);\n"
    "		if(TimersMeta)\n"
    "		{\n"
    "			for(var i = 0; i < nMetaLen; ++i)\n"
    "			{\n"
    "				DrawHeaderSplitSingle(MetaNames[i], MetaLengths[i] * FontWidth);\n"
    "				DrawHeaderSplitSingle(MetaNames[i] + \" Avg\", MetaLengthsAvg[i] * FontWidth);\n"
    "				DrawHeaderSplitSingle(MetaNames[i] + \" Max\", MetaLengthsMax[i] * FontWidth);\n"
    "			}\n"
    "		}\n"
    "		X = 0;\n"
    "		context.fillStyle = nBackColorOffset;\n"
    "		context.fillRect(0, 0, NameWidth, Height);\n"
    "		context.fillStyle = \'white\';\n"
    "	\n"
    "		DrawHeaderSplitLeftRight(StrGroup, StrTimer, NameWidth);\n"
    "	\n"
    "	}\n"
    "\n"
    "	ProfileLeave();\n"
    "}\n"
    "\n"
    "var CounterNameWidth = 100;\n"
    "var CounterValueWidth = 100;\n"
    "var CounterLimitWidth = 100;\n"
    "\n"
    "var FormatCounterDefault = 0;\n"
    "var FormatCounterBytes = 1;\n"
    "var FormatCounterBytesExt = [ \"b\",\"kb\",\"mb\",\"gb\",\"tb\",\"pb\", \"eb\",\"zb\", \"yb\" ];\n"
    "\n"
    "function FormatCounter(Format, Counter)\n"
    "{\n"
    "	if(!Counter)\n"
    "	{\n"
    "		return \'0\';\n"
    "	}\n"
    "	var Negative = 0;\n"
    "	if(Counter < 0)\n"
    "	{\n"
    "		Counter = -Counter;\n"
    "		Negative = 1;\n"
    "		if(Counter < 0) // handle INT_MIN\n"
    "		{\n"
    "			Counter = -(Counter+1);\n"
    "			if(Counter < 0)\n"
    "			{\n"
    "				return \'?\';\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "	var str = Negative ? \'-\' :\'\' ;\n"
    "	if(Format == FormatCounterDefault)\n"
    "	{\n"
    "		var Seperate = 0;\n"
    "		var result = \'\';\n"
    "		while (Counter)\n"
    "		{\n"
    "			if (Seperate)\n"
    "			{\n"
    "				result += \'.\';\n"
    "			}\n"
    "			Seperate = 1;\n"
    "			for (var i = 0; Counter && i < 3; ++i)\n"
    "			{\n"
    "				var Digit = Math.floor(Counter % 10);\n"
    "				Counter = Math.floor(Counter / 10);\n"
    "				result += \'\' + Digit;\n"
    "			}\n"
    "		}\n"
    "\n"
    "		for(var i = 0; i < result.length; ++i)\n"
    "		{\n"
    "			str += result[result.length-1-i];\n"
    "		}\n"
    "		return str;\n"
    "	}\n"
    "	else if(Format == FormatCounterBytes)\n"
    "	{\n"
    "		var Shift = 0;\n"
    "		var Divisor = 1;\n"
    "		var CountShifted = Counter >> 10;\n"
    "		while(CountShifted)\n"
    "		{\n"
    "			Divisor <<= 10;\n"
    "			CountShifted >>= 10;\n"
    "			Shift++;\n"
    "		}\n"
    "		if(Shift)\n"
    "		{\n"
    "			return str + (Counter / Divisor).toFixed(2) + \'\' + FormatCounterBytesExt[Shift];\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			return str + Counter.toFixed(2) + \'\' + FormatCounterBytesExt[0];\n"
    "		}\n"
    "	}\n"
    "	return \'?\'\n"
    "}\n"
    "function DrawCounterView()\n"
    "{\n"
    "	ProfileEnter(\"DrawCounterView\");\n"
    "	Invalidate++;\n"
    "	nHoverToken = -1;\n"
    "	nHoverFrame = -1;\n"
    "	var context = CanvasDetailedView.getContext(\'2d\');\n"
    "	context.clearRect(0, 0, nWidth, nHeight);\n"
    "\n"
    "	var Height = BoxHeight;\n"
    "	var Width = nWidth;\n"
    "	//clamp offset to prevent scrolling into the void\n"
    "	var nTotalRows = CounterInfo.length;\n"
    "	var nTotalRowPixels = nTotalRows * Height;\n"
    "	var nFrameRows = nHeight - BoxHeight;\n"
    "	if(nOffsetCountersY + nFrameRows > nTotalRowPixels && nTotalRowPixels > nFrameRows)\n"
    "	{\n"
    "		nOffsetCountersY = nTotalRowPixels - nFrameRows;\n"
    "	}\n"
    "\n"
    "	var CounterNameWidthTemp = 10;\n"
    "	var CounterValueWidthTemp = 10;\n"
    "	var CounterLimitWidthTemp = 10;\n"
    "\n"
    "	var CounterWidth = 150;\n"
    "	var Y = -nOffsetCountersY + BoxHeight;\n"
    "	var X = 0;\n"
    "	var nColorIndex = 0;\n"
    "	context.fillStyle = \'white\';\n"
    "	context.font = Font;\n"
    "	var bMouseIn = 0;\n"
    "	function DrawHeaderSplitSingle(Header, Width)\n"
    "	{\n"
    "		context.fillStyle = \'white\';\n"
    "		context.fillText(Header, X, Height-FontAscent);\n"
    "		X += Width;\n"
    "		context.fillStyle = nBackColorOffset;\n"
    "		context.fillRect(X-3, 0, 1, nHeight);\n"
    "	}\n"
    "	function DrawHeaderSplitSingleRight(Header, Width)\n"
    "	{\n"
    "		X += Width;\n"
    "		context.fillStyle = \'white\';\n"
    "		context.textAlign  = \'right\';\n"
    "		context.fillText(Header, X - FontWidth, Height-FontAscent);\n"
    "		context.fillStyle = nBackColorOffset;\n"
    "		context.fillRect(X, 0, 1, nHeight);\n"
    "		context.textAlign  = \'left\';\n"
    "	}\n"
    "	var TimerLen = 6;\n"
    "	var TimerWidth = TimerLen * FontWidth;\n"
    "	nHoverCounter = -1;\n"
    "	function CounterIndent(Level)\n"
    "	{\n"
    "		return Level * 4 * FontWidth;\n"
    "	}\n"
    "	function Max(a, b)\n"
    "	{\n"
    "		return a > b ? a : b;\n"
    "	}\n"
    "\n"
    "	function DrawCounterRecursive(Index)\n"
    "	{\n"
    "		var Counter = CounterInfo[Index];\n"
    "		var Indent = CounterIndent(Counter.level);\n"
    "		CounterNameWidthTemp = Max(CounterNameWidthTemp, Counter.name.length+1 + Indent / (FontWidth+1));\n"
    "		CounterValueWidthTemp = Max(CounterValueWidthTemp, Counter.formatted.length);\n"
    "		CounterLimitWidthTemp = Max(CounterLimitWidthTemp, Counter.formattedlimit.length);\n"
    "\n"
    "		var X = 0;\n"
    "		nColorIndex = 1-nColorIndex;\n"
    "		var HeightExpanded = Counter.Expanded ? Height * 5 : Height\n"
    "\n"
    "		bMouseIn = DetailedViewMouseY >= Y && DetailedViewMouseY < Y + HeightExpanded;\n"
    "		if(bMouseIn)\n"
    "		{\n"
    "			nHoverCounter = Index;\n"
    "		}\n"
    "		var bgcolor = bMouseIn ? nBackColorOffset : nBackColors[nColorIndex];\n"
    "		context.fillStyle = bgcolor;\n"
    "		context.fillRect(0, Y, Width, HeightExpanded);\n"
    "		context.fillStyle = \'white\';\n"
    "		var c = Counter.closed ? \'*\' : \' \';\n"
    "		context.fillText(c + Counter.name, Indent, Y+Height-FontAscent);\n"
    "		X += CounterNameWidth;\n"
    "		X += CounterValueWidth - FontWidth;\n"
    "		context.textAlign = \'right\';\n"
    "		context.fillText(Counter.formatted, X, Y+Height-FontAscent);\n"
    "		context.textAlign = \'left\';\n"
    "		X += FontWidth * 4;\n"
    "		var Y0 = Y + 1;\n"
    "		if(Counter.limit != 0)\n"
    "		{\n"
    "			context.fillText(Counter.formattedlimit, X, Y+Height-FontAscent);\n"
    "			X += CounterLimitWidth;\n"
    "			var X0 = X + 1;\n"
    "			context.fillStyle = \'white\';\n"
    "			context.fillRect(X0, Y0, Counter.boxprc * (CounterWidth-2), Height-2);\n"
    "			context.fillStyle = bgcolor;\n"
    "			context.fillRect(X0+1, Y0+1, Counter.boxprc * (CounterWidth-4), Height-4);\n"
    "			context.fillStyle = \'cyan\';\n"
    "			context.fillRect(X0+1, Y0+1, Counter.counterprc * (CounterWidth-4), Height-4);\n"
    "			X += CounterWidth + 10;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			X += CounterLimitWidth;\n"
    "			X += CounterWidth + 10;\n"
    "		}\n"
    "		if(Counter.historydata.length > 0)\n"
    "		{\n"
    "			var Prc = Counter.historyprc;\n"
    "			var Data = Counter.historydata;\n"
    "\n"
    "			context.fillStyle = \'cyan\';\n"
    "			context.strokeStyle = \'cyan\';\n"
    "			context.globalAlpha = 0.5;\n"
    "			context.beginPath();\n"
    "			var x = X;\n"
    "			var YBase = Y0 + HeightExpanded-1;\n"
    "			var YOffset = -(HeightExpanded-2);\n"
    "\n"
    "			context.moveTo(X, Y0);\n"
    "			for(var i = 0; i < Prc.length; ++i)\n"
    "			{\n"
    "				context.moveTo(x, YBase);\n"
    "				context.lineTo(x, YBase + Prc[i] * YOffset);\n"
    "\n"
    "				x += 1;\n"
    "			}\n"
    "			context.stroke();\n"
    "\n"
    "			x = X;\n"
    "			context.globalAlpha = 1.0;\n"
    "			context.beginPath();\n"
    "			context.moveTo(X, YBase);\n"
    "\n"
    "			for(var i = 0; i < Prc.length; ++i)\n"
    "			{\n"
    "				context.lineTo(x, YBase + Prc[i] * YOffset);\n"
    "				x += 1;\n"
    "			}\n"
    "			context.stroke();\n"
    "			if(bMouseIn)\n"
    "			{\n"
    "				var MouseGraphX = Math.floor(DetailedViewMouseX - X);\n"
    "				if(MouseGraphX >= 0 && MouseGraphX < Data.length)\n"
    "				{\n"
    "					context.fillStyle = \'white\';\n"
    "					var Formatted = FormatCounter(Counter.format, Data[MouseGraphX]);\n"
    "					context.fillText(Formatted, X, Y+Height-FontAscent);\n"
    "				}\n"
    "				context.strokeStyle = \'orange\';\n"
    "				context.beginPath();\n"
    "				var CrossX = X + MouseGraphX;\n"
    "				var CrossY = YBase + Prc[MouseGraphX] * YOffset;\n"
    "				context.moveTo(CrossX-2, CrossY-2);\n"
    "				context.lineTo(CrossX+2, CrossY+2);\n"
    "				context.moveTo(CrossX+2, CrossY-2);\n"
    "				context.lineTo(CrossX-2, CrossY+2);\n"
    "				context.stroke();\n"
    "\n"
    "			}\n"
    "			X += Prc.length + 5;\n"
    "			context.fillStyle = \'white\';\n"
    "			context.fillText( FormatCounter(Counter.format, Counter.minvalue), X, Y + Height - FontAscent);\n"
    "			X += CounterWidth + 5;\n"
    "			context.fillText( FormatCounter(Counter.format, Counter.maxvalue), X, Y + Height - FontAscent);\n"
    "			X += CounterWidth + 5;\n"
    "		}\n"
    "\n"
    "		Y += HeightExpanded;\n"
    "\n"
    "		if(!Counter.closed)\n"
    "		{\n"
    "			var ChildIndex = Counter.firstchild;\n"
    "			while(ChildIndex != -1)\n"
    "			{\n"
    "				DrawCounterRecursive(ChildIndex);\n"
    "				ChildIndex = CounterInfo[ChildIndex].sibling;\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "\n"
    "	for(var i = 0; i < CounterInfo.length; ++i)\n"
    "	{\n"
    "		if(CounterInfo[i].parent == -1)\n"
    "		{\n"
    "			DrawCounterRecursive(i);\n"
    "		}\n"
    "	}\n"
    "\n"
    "	X = 0;\n"
    "	context.fillStyle = nBackColorOffset;\n"
    "	context.fillRect(0, 0, Width, Height);\n"
    "	context.fillStyle = \'white\';\n"
    "	DrawHeaderSplitSingle(\'Name\', CounterNameWidth);\n"
    "	DrawHeaderSplitSingleRight(\'Value\', CounterValueWidth + (FontWidth+1));\n"
    "	DrawHeaderSplitSingle(\'Limit\', CounterLimitWidth + CounterWidth + 3 * (FontWidth+1));\n"
    "\n"
    "\n"
    "\n"
    "\n"
    "\n"
    "	var CounterNameWidthNew = CounterNameWidthTemp * (FontWidth+1);\n"
    "	var CounterValueWidthNew = CounterValueWidthTemp * (FontWidth+1);\n"
    "	var CounterLimitWidthNew = CounterLimitWidthTemp * (FontWidth+1);\n"
    "	if(CounterNameWidthNew != CounterNameWidth || CounterValueWidthNew != CounterValueWidth || CounterLimitWidthNew != "
    "CounterLimitWidth)\n"
    "	{\n"
    "		// console.log(\'requesting redraw 0\' + CounterNameWidthNew + \'= \' + CounterNameWidth );\n"
    "		// console.log(\'requesting redraw 1\' + CounterValueWidthNew + \'= \' + CounterValueWidth );\n"
    "		// console.log(\'requesting redraw 2\' + CounterLimitWidthNew + \'= \' + CounterLimitWidth );\n"
    "		CounterNameWidth = CounterNameWidthNew;\n"
    "		CounterValueWidth = CounterValueWidthNew;\n"
    "		CounterLimitWidth = CounterLimitWidthNew;\n"
    "		Invalidate = 0;\n"
    "	}\n"
    "\n"
    "	ProfileLeave();\n"
    "}\n"
    "\n"
    "\n"
    "//preprocess context switch data to contain array per thread\n"
    "function PreprocessContextSwitchCacheItem(ThreadId)\n"
    "{\n"
    "	var CSObject = CSwitchCache[ThreadId];\n"
    "	if(ThreadId > 0 && !CSObject)\n"
    "	{\n"
    "		CSArrayIn = new Array();\n"
    "		CSArrayOut = new Array();\n"
    "		CSArrayCpu = new Array();\n"
    "		var nCount = CSwitchTime.length;\n"
    "		var j = 0;\n"
    "		var TimeIn = -1.0;\n"
    "		for(var i = 0; i < nCount; ++i)\n"
    "		{	\n"
    "			var ThreadIn = CSwitchThreadInOutCpu[j];\n"
    "			var ThreadOut = CSwitchThreadInOutCpu[j+1];\n"
    "			var Cpu = CSwitchThreadInOutCpu[j+2];\n"
    "			if(TimeIn < 0)\n"
    "			{\n"
    "				if(ThreadIn == ThreadId)\n"
    "				{\n"
    "					TimeIn = CSwitchTime[i];\n"
    "				}\n"
    "			}\n"
    "			else\n"
    "			{\n"
    "				if(ThreadOut == ThreadId)\n"
    "				{\n"
    "					var TimeOut = CSwitchTime[i];\n"
    "					CSArrayIn.push(TimeIn);\n"
    "					CSArrayOut.push(TimeOut);\n"
    "					CSArrayCpu.push(Cpu);\n"
    "					TimeIn = -1;\n"
    "				}\n"
    "			}\n"
    "			j += 3;\n"
    "		}\n"
    "		CSObject = new Object();\n"
    "		CSObject.Size = CSArrayIn.length;\n"
    "		CSObject.In = CSArrayIn;\n"
    "		CSObject.Out = CSArrayOut;\n"
    "		CSObject.Cpu = CSArrayCpu;\n"
    "		CSwitchCache[ThreadId] = CSObject;\n"
    "	}\n"
    "\n"
    "}\n"
    "function PreprocessContextSwitchCache()\n"
    "{\n"
    "	ProfileEnter(\"PreprocessContextSwitchCache\");\n"
    "	var AllThreads = {};\n"
    "	var nCount = CSwitchTime.length;\n"
    "	for(var i = 0; i < nCount; ++i)\n"
    "	{	\n"
    "		var nThreadIn = CSwitchThreadInOutCpu[i];\n"
    "		if(!AllThreads[nThreadIn])\n"
    "		{\n"
    "		    AllThreads[nThreadIn] = \'\' + nThreadIn;\n"
    "		    var FoundThread = false;\n"
    "		    for(var i = 0; i < ThreadIds.length; ++i)\n"
    "		    {\n"
    "		        if(ThreadIds[i] == nThreadIn)\n"
    "		        {\n"
    "		            FoundThread = true;\n"
    "		        }\n"
    "		    }\n"
    "		    if(!FoundThread)\n"
    "		    {\n"
    "		        CSwitchOnlyThreads.push(nThreadIn);\n"
    "		    }\n"
    "		}\n"
    "	}\n"
    "	for(var i = 0; i < CSwitchOnlyThreads.length; ++i)\n"
    "	{\n"
    "		PreprocessContextSwitchCacheItem(CSwitchOnlyThreads[i]);\n"
    "	}\n"
    "	for(var i = 0; i < ThreadIds.length; ++i)\n"
    "	{\n"
    "		PreprocessContextSwitchCacheItem(ThreadIds[i]);	\n"
    "	}\n"
    "	function HandleMissingThread(a)\n"
    "	{\n"
    "		if(!CSwitchThreads[a])\n"
    "		{\n"
    "			CSwitchThreads[a] = {\'tid\':a, \'pid\':-1, \'t\':\'?\', \'p\':\'?\'}\n"
    "		}\n"
    "	}\n"
    "	function CompareThreadInfo(a, b)\n"
    "	{\n"
    "		if(a.pid != b.pid)\n"
    "			return b.pid - a.pid;\n"
    "		else\n"
    "			return a.tid - b.tid;\n"
    "	}\n"
    "	CSwitchOnlyThreads.sort( function(a, b){ \n"
    "		HandleMissingThread(a);\n"
    "		HandleMissingThread(b);\n"
    "		return CompareThreadInfo(CSwitchThreads[a], CSwitchThreads[b]); \n"
    "	} );\n"
    "\n"
    "	ProfileLeave();\n"
    "}\n"
    "\n"
    "function DrawContextSwitchBars(context, ThreadId, fScaleX, fOffsetY, fDetailedOffset, nHoverColor, MinWidth, bDrawEnabled)\n"
    "{\n"
    "	ProfileEnter(\"DrawContextSwitchBars\");\n"
    "	var CSObject = CSwitchCache[ThreadId];\n"
    "	if(CSObject)\n"
    "	{\n"
    "		var Size = CSObject.Size;		\n"
    "		var In = CSObject.In;\n"
    "		var Out = CSObject.Out;\n"
    "		var Cpu = CSObject.Cpu;\n"
    "		var nNumColors = CSwitchColors.length;\n"
    "		for(var i = 0; i < Size; ++i)\n"
    "		{\n"
    "			var TimeIn = In[i];\n"
    "			var TimeOut = Out[i];\n"
    "			var ActiveCpu = Cpu[i];\n"
    "\n"
    "			var X = (TimeIn - fDetailedOffset) * fScaleX;\n"
    "			if(X > nWidth)\n"
    "			{\n"
    "				break;\n"
    "			}\n"
    "			var W = (TimeOut - TimeIn) * fScaleX;\n"
    "			if(W > MinWidth && X+W > 0)\n"
    "			{\n"
    "				if(nHoverCSCpu == ActiveCpu || bDrawEnabled)\n"
    "				{\n"
    "					if(nHoverCSCpu == ActiveCpu)\n"
    "					{\n"
    "						context.fillStyle = nHoverColor;\n"
    "					}\n"
    "					else\n"
    "					{\n"
    "						context.fillStyle = CSwitchColors[ActiveCpu % nNumColors];\n"
    "					}\n"
    "					context.fillRect(X, fOffsetY, W, CSwitchHeight);\n"
    "				}\n"
    "				if(DetailedViewMouseX >= X && DetailedViewMouseX <= X+W && DetailedViewMouseY < fOffsetY+CSwitchHeight && "
    "DetailedViewMouseY >= fOffsetY)\n"
    "				{\n"
    "					nHoverCSCpuNext = ActiveCpu;\n"
    "					RangeCpuNext.Begin = TimeIn;\n"
    "					RangeCpuNext.End = TimeOut;\n"
    "					RangeCpuNext.Thread = ThreadId;\n"
    "					RangeGpuNext.Begin = RangeGpuNext.End = -1;\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "	ProfileLeave();\n"
    "}\n"
    "\n"
    "function SetHoverToken(nToken, nIndex, nLog)\n"
    "{\n"
    "	for(var i = Frames.length-1; i >= 0; --i)\n"
    "	{\n"
    "		var IndexStart = LodData[0].LogStart[i][nLog];\n"
    "		if(nIndex >= IndexStart)\n"
    "		{\n"
    "			nHoverFrame = i;\n"
    "			nHoverTokenNext = nToken;\n"
    "			nHoverTokenIndexNext = nIndex - IndexStart;\n"
    "			nHoverTokenLogIndexNext = nLog;\n"
    "			break;\n"
    "		}\n"
    "	}\n"
    "}\n"
    "\n"
    "function DrawDetailedView(context, MinWidth, bDrawEnabled)\n"
    "{\n"
    "	if(bDrawEnabled)\n"
    "	{\n"
    "		DrawDetailedBackground(context);\n"
    "	}\n"
    "\n"
    "	var colors = [ \'#ff0000\', \'#ff00ff\', \'#ffff00\'];\n"
    "\n"
    "	var fScaleX = nWidth / fDetailedRange; \n"
    "	var fOffsetY = -nOffsetY + BoxHeight;\n"
    "	nHoverTokenNext = -1;\n"
    "	nHoverTokenLogIndexNext = -1;\n"
    "	nHoverTokenIndexNext = -1;\n"
    "	nHoverCounter += nHoverCounterDelta;\n"
    "	if(nHoverCounter >= 255) \n"
    "	{\n"
    "		nHoverCounter = 255;\n"
    "		nHoverCounterDelta = -nHoverCounterDelta;\n"
    "	}\n"
    "	if(nHoverCounter < 128) \n"
    "	{\n"
    "		nHoverCounter = 128;\n"
    "		nHoverCounterDelta = -nHoverCounterDelta;\n"
    "	}\n"
    "	var nHoverHigh = nHoverCounter.toString(16);\n"
    "	var nHoverLow = (127+255-nHoverCounter).toString(16);\n"
    "	var nHoverColor = \'#\' + nHoverHigh + nHoverHigh + nHoverHigh;\n"
    "\n"
    "	context.fillStyle = \'black\';\n"
    "	context.font = Font;\n"
    "	var nNumLogs = Frames[0].ts.length;\n"
    "	var fTimeEnd = fDetailedOffset + fDetailedRange;\n"
    "\n"
    "	var FirstFrame = 0;\n"
    "	for(var i = 0; i < Frames.length ; i++)\n"
    "	{\n"
    "		if(Frames[i].frameend < fDetailedOffset)\n"
    "		{\n"
    "			FirstFrame = i;\n"
    "		}\n"
    "	}\n"
    "	var nMinTimeMs = MinWidth / fScaleX;\n"
    "	{\n"
    "\n"
    "		var Batches = new Array(TimerInfo.length);\n"
    "		var BatchesTxt = Array();\n"
    "		var BatchesTxtPos = Array();\n"
    "		var BatchesTxtColor = [\'#ffffff\', \'#333333\'];\n"
    "		if(!ThreadY)\n"
    "		{\n"
    "			ThreadY = new Array(ThreadNames.length+1);\n"
    "		}\n"
    "\n"
    "		for(var i = 0; i < 2; ++i)\n"
    "		{\n"
    "			BatchesTxt[i] = Array();\n"
    "			BatchesTxtPos[i] = Array();\n"
    "		}\n"
    "		for(var i = 0; i < Batches.length; ++i)\n"
    "		{\n"
    "			Batches[i] = Array();\n"
    "		}\n"
    "		for(nLog = 0; nLog < nNumLogs; nLog++)\n"
    "		{\n"
    "			var ThreadName = ThreadNames[nLog];\n"
    "			ThreadY[nLog] = fOffsetY;\n"
    "			if(ThreadsAllActive || ThreadsActive[ThreadName])\n"
    "			{\n"
    "				var LodIndex = 0;\n"
    "				var MinDelta = 0;\n"
    "				var NextLod = 1;\n"
    "				while(NextLod < LodData.length && LodData[NextLod].MinDelta[nLog] < nMinTimeMs)\n"
    "				{\n"
    "					LodIndex = NextLod;\n"
    "					NextLod = NextLod + 1;\n"
    "					MinDelta = LodData[LodIndex].MinDelta[nLog];\n"
    "				}\n"
    "				if(LodIndex == LodData.length)\n"
    "				{\n"
    "					LodIndex = LodData.length-1;\n"
    "				}\n"
    "				if(DisableLod)\n"
    "				{\n"
    "					LodIndex = 0;\n"
    "				}\n"
    "\n"
    "				context.fillStyle = \'white\';\n"
    "				fOffsetY += BoxHeight;\n"
    "				context.fillText(ThreadName, 0, fOffsetY);\n"
    "				if(nContextSwitchEnabled)\n"
    "				{\n"
    "					DrawContextSwitchBars(context, ThreadIds[nLog], fScaleX, fOffsetY, fDetailedOffset, nHoverColor, MinWidth, "
    "bDrawEnabled);\n"
    "					fOffsetY += CSwitchHeight+1;\n"
    "				}\n"
    "				var MaxDepth = 1;\n"
    "				var StackPos = 0;\n"
    "				var Stack = Array(20);\n"
    "				var Lod = LodData[LodIndex];\n"
    "\n"
    "				var TypeArray = g_TypeArray[nLog];\n"
    "				var TimeArray = g_TimeArray[nLog];\n"
    "				var IndexArray = g_IndexArray[nLog];\n"
    "				var LabelArray = g_LabelArray[nLog];\n"
    "				var GlobalArray = Lod.GlobalArray[nLog];\n"
    "\n"
    "				var LocalFirstFrame = Frames[FirstFrame].FirstFrameIndex[nLog];\n"
    "				var IndexStart = Lod.LogStart[LocalFirstFrame][nLog];\n"
    "				var IndexEnd = GlobalArray.length;\n"
    "\n"
    "				for(var j = IndexStart; j < IndexEnd; ++j)\n"
    "				{\n"
    "					var glob = GlobalArray[j];\n"
    "					var type = TypeArray[glob];\n"
    "					var index = IndexArray[glob];\n"
    "					var time = TimeArray[glob];\n"
    "					if(type == 1)\n"
    "					{\n"
    "						Stack[StackPos] = glob;\n"
    "						StackPos++;\n"
    "						if(StackPos > MaxDepth)\n"
    "						{\n"
    "							MaxDepth = StackPos;\n"
    "						}\n"
    "					}\n"
    "					else if(type == 0)\n"
    "					{\n"
    "						if(StackPos>0)\n"
    "						{\n"
    "							StackPos--;\n"
    "\n"
    "							var globstart = Stack[StackPos];\n"
    "							var timestart = TimeArray[globstart];\n"
    "							var timeend = time;\n"
    "							var X = (timestart - fDetailedOffset) * fScaleX;\n"
    "							var Y = fOffsetY + StackPos * BoxHeight;\n"
    "							var W = (timeend-timestart)*fScaleX;\n"
    "\n"
    "							if(W > MinWidth && X < nWidth && X+W > 0)\n"
    "		";

const size_t g_ProfileHtml_end_1_size = sizeof(g_ProfileHtml_end_1);
const char   g_ProfileHtml_end_2[] =
    "					{\n"
    "								if(bDrawEnabled || index == nHoverToken)\n"
    "								{\n"
    "									Batches[index].push(X);\n"
    "									Batches[index].push(Y);\n"
    "									Batches[index].push(W);\n"
    "									DebugDrawQuadCount++;\n"
    "\n"
    "									var XText = X < 0 ? 0 : X;\n"
    "									var WText = W - (XText-X);\n"
    "									if(XText + WText > nWidth)\n"
    "									{\n"
    "										WText = nWidth - XText;\n"
    "									}\n"
    "									var Name = LabelArray[globstart] ? LabelArray[globstart] : TimerInfo[index].name;\n"
    "									var BarTextLen = Math.floor((WText-2)/FontWidth);\n"
    "									var TimeText = TimeToMsString(timeend-timestart);\n"
    "									var TimeTextLen = TimeText.length;\n"
    "\n"
    "									if(BarTextLen >= 2)\n"
    "									{\n"
    "										if(BarTextLen < Name.length)\n"
    "											Name = Name.substr(0, BarTextLen);\n"
    "										var txtidx = TimerInfo[index].textcolorindex;\n"
    "										var YPos = Y+BoxHeight-FontAscent;\n"
    "										BatchesTxt[txtidx].push(Name);\n"
    "										BatchesTxtPos[txtidx].push(XText+2);\n"
    "\n"
    "										BatchesTxtPos[txtidx].push(YPos);\n"
    "										DebugDrawTextCount++;\n"
    "										if(BarTextLen - Name.length > TimeTextLen)\n"
    "										{\n"
    "											BatchesTxt[txtidx].push(TimeText);\n"
    "											BatchesTxtPos[txtidx].push(XText+WText-2 - TimeTextLen * FontWidth);\n"
    "											BatchesTxtPos[txtidx].push(YPos);\n"
    "											DebugDrawTextCount++;\n"
    "										}\n"
    "\n"
    "									}\n"
    "								}\n"
    "\n"
    "								if(DetailedViewMouseX >= X && DetailedViewMouseX <= X+W && DetailedViewMouseY < Y+BoxHeight && "
    "DetailedViewMouseY >= Y)\n"
    "								{\n"
    "									RangeCpuNext.Begin = timestart;\n"
    "									RangeCpuNext.End = timeend;\n"
    "									RangeCpuNext.Thread = nLog;\n"
    "\n"
    "									if(TypeArray[globstart+1] == 4 && TypeArray[glob+1] == 4)\n"
    "									{\n"
    "										RangeGpuNext.Begin = RangeCpuNext.Begin;\n"
    "										RangeGpuNext.End = RangeCpuNext.End;\n"
    "										RangeGpuNext.Thread = nLog;\n"
    "										//cpu tick is stored following\n"
    "										RangeCpuNext.Begin = TimeArray[globstart+1];\n"
    "										RangeCpuNext.End = TimeArray[glob+1];\n"
    "										RangeCpuNext.Thread = IndexArray[globstart+1];\n"
    "									}\n"
    "									else\n"
    "									{\n"
    "										RangeGpuNext.Begin = -1;\n"
    "										RangeGpuNext.End = -1\n"
    "									}\n"
    "\n"
    "									SetHoverToken(index, glob, nLog)\n"
    "								}\n"
    "							}\n"
    "							if(StackPos == 0 && time > fTimeEnd)\n"
    "								break;											\n"
    "						}\n"
    "					}\n"
    "				}\n"
    "				fOffsetY += (1+g_MaxStack[nLog]) * BoxHeight;\n"
    "			}\n"
    "			ThreadY[nLog+1] = fOffsetY;\n"
    "		}\n"
    "\n"
    "		if(nContextSwitchEnabled) //non instrumented threads.\n"
    "		{\n"
    "			var CurrentPid = -112;\n"
    "			var ContextSwitchThreads = CSwitchOnlyThreads;\n"
    "			function DrawHeader(str, X, Y)\n"
    "			{\n"
    "				var width = str.length * FontWidth;\n"
    "				context.globalAlpha = 0.5;\n"
    "				context.fillStyle = \'grey\';\n"
    "				context.fillRect(X, Y-FontHeight + 2, width, FontHeight);\n"
    "				context.globalAlpha = 1.0;\n"
    "				context.fillStyle = \'white\';\n"
    "				context.fillText(str, X, Y);\n"
    "\n"
    "\n"
    "			}\n"
    "			for(var i = 0; i < ContextSwitchThreads.length; ++i)\n"
    "			{\n"
    "				var ThreadId = ContextSwitchThreads[i];\n"
    "				var ThreadName = \'\' + ThreadId;\n"
    "				var TI = CSwitchThreads[ThreadId];\n"
    "\n"
    "				if(TI)\n"
    "				{\n"
    "					if(CurrentPid != TI.pid)\n"
    "					{\n"
    "						fOffsetY += BoxHeight + 1;\n"
    "						CurrentPid = TI.pid;\n"
    "						var str = TI.pid.toString(16) +\':\' +TI.p;\n"
    "						DrawHeader(str, 0, fOffsetY+5);\n"
    "						fOffsetY += BoxHeight + 1;\n"
    "					}\n"
    "				}\n"
    "\n"
    "				DrawContextSwitchBars(context, ThreadId, fScaleX, fOffsetY, fDetailedOffset, nHoverColor, MinWidth, bDrawEnabled);\n"
    "\n"
    "				if(TI)\n"
    "				{\n"
    "					DrawHeader(TI.tid.toString(16) +\':\' +TI.t, 10, fOffsetY+5);\n"
    "				}\n"
    "				fOffsetY += BoxHeight + 1;\n"
    "			}\n"
    "		}\n"
    "\n"
    "\n"
    "		{\n"
    "			for(var i = 0; i < Batches.length; ++i)\n"
    "			{\n"
    "				var a = Batches[i];\n"
    "				if(a.length)\n"
    "				{\n"
    "					if(!DisableMerge)\n"
    "					{\n"
    "						for(var j = 0; j < a.length; j += 3)\n"
    "						{						\n"
    "							var X = a[j];\n"
    "							var Y = a[j+1];\n"
    "							var BaseWidth = j + 2;\n"
    "							var W = a[BaseWidth];\n"
    "							while(j+1 < a.length && W < 1)\n"
    "							{\n"
    "								var jnext = j+3;\n"
    "								var XNext = a[jnext];\n"
    "								var YNext = a[jnext+1];\n"
    "								var WNext = a[jnext+2];\n"
    "								var Delta = XNext - (X+W);\n"
    "								var YDelta = Math.abs(Y - YNext);							\n"
    "								if(Delta < 0.3 && YDelta < 0.5 && WNext < 1)\n"
    "								{\n"
    "									W = (XNext+WNext) - X;\n"
    "									a[BaseWidth] = W;\n"
    "									a[jnext+2] = 0;\n"
    "									j += 3;\n"
    "								}\n"
    "								else\n"
    "								{\n"
    "									break;\n"
    "								}\n"
    "\n"
    "							}\n"
    "						}\n"
    "					}\n"
    "					var off = 0.7;\n"
    "					var off2 = 2*off;\n"
    "					context.fillStyle = TimerInfo[i].colordark;\n"
    "					for(var j = 0; j < a.length; j += 3)\n"
    "					{						\n"
    "						var X = a[j];\n"
    "						var Y = a[j+1];\n"
    "						var W = a[j+2];\n"
    "						if(W >= 1)\n"
    "						{\n"
    "							context.fillRect(X, Y, W, BoxHeight-1);\n"
    "						}\n"
    "					}\n"
    "	\n"
    "\n"
    "					if(i == nHoverToken)\n"
    "					{\n"
    "						context.fillStyle = nHoverColor;\n"
    "					}\n"
    "					else\n"
    "					{\n"
    "						context.fillStyle = TimerInfo[i].color;\n"
    "					}\n"
    "					for(var j = 0; j < a.length; j += 3)\n"
    "					{						\n"
    "						var X = a[j];\n"
    "						var Y = a[j+1];\n"
    "						var W = a[j+2];\n"
    "						if(W > 0)\n"
    "						{\n"
    "							context.fillRect(X+off, Y+off, W-off2, BoxHeight-1-off2);\n"
    "						}\n"
    "					}\n"
    "				}\n"
    "			}	\n"
    "		}\n"
    "		for(var i = 0; i < BatchesTxt.length; ++i)\n"
    "		{\n"
    "			context.fillStyle = BatchesTxtColor[i];\n"
    "			var TxtArray = BatchesTxt[i];\n"
    "			var PosArray = BatchesTxtPos[i];\n"
    "			for(var j = 0; j < TxtArray.length; ++j)\n"
    "			{\n"
    "				var k = j * 2;\n"
    "				context.fillText(TxtArray[j], PosArray[k],PosArray[k+1]);\n"
    "			}\n"
    "		}\n"
    "\n"
    "	}\n"
    "}\n"
    "function DrawTextBox(context, text, x, y, align)\n"
    "{\n"
    "	var textsize = context.measureText(text).width;\n"
    "	var offsetx = 0;\n"
    "	var offsety = -FontHeight;\n"
    "	if(align == \'center\')\n"
    "	{\n"
    "		offsetx = -textsize / 2.0;\n"
    "	}\n"
    "	else if(align == \'right\')\n"
    "	{\n"
    "		offsetx = -textsize;\n"
    "	}\n"
    "	context.fillStyle = nBackColors[0];\n"
    "	context.fillRect(x + offsetx, y + offsety, textsize+2, FontHeight + 2);\n"
    "	context.fillStyle = \'white\';\n"
    "	context.fillText(text, x, y);\n"
    "\n"
    "}\n"
    "function DrawRange(context, Range, ColorBack, ColorFront, Name)\n"
    "{\n"
    "	var fBegin = Range.Begin;\n"
    "	var fEnd = Range.End;\n"
    "	var OffsetTop = Range.YBegin;\n"
    "	var OffsetBottom = Range.YEnd;\n"
    "	if(fBegin < fEnd)\n"
    "	{\n"
    "		var MarginTop = 0.5 * FontHeight;\n"
    "		var MarginBottom = nHeight - 1.5 * FontHeight;\n"
    "		if(OffsetTop < MarginTop)\n"
    "			OffsetTop = MarginTop;\n"
    "		if(OffsetBottom > MarginBottom)\n"
    "			OffsetBottom = MarginBottom;\n"
    "		var fRulerOffset = FontHeight * 0.5;\n"
    "		var fScaleX = nWidth / fDetailedRange; \n"
    "		var X = (fBegin - fDetailedOffset) * fScaleX;\n"
    "		var YSpace = (FontHeight+2);\n"
    "		var Y = OffsetTop;\n"
    "		var YBottom = OffsetBottom;\n"
    "		var W = (fEnd - fBegin) * fScaleX;\n"
    "		context.globalAlpha = 0.1;\n"
    "		context.fillStyle = ColorBack;\n"
    "		context.fillRect(X, OffsetTop + fRulerOffset, W, OffsetBottom - OffsetTop);\n"
    "		context.globalAlpha = 1;\n"
    "		context.strokeStyle = ColorFront;\n"
    "		context.beginPath();\n"
    "		context.moveTo(X, 0);\n"
    "		context.lineTo(X, nHeight);\n"
    "		context.moveTo(X+W, 0);\n"
    "		context.lineTo(X+W, nHeight);\n"
    "		context.stroke();\n"
    "		var Duration = (fEnd - fBegin).toFixed(2) + \"ms\";\n"
    "		var Center = ((fBegin + fEnd) / 2.0) - fDetailedOffset;\n"
    "		var DurationWidth = context.measureText(Duration+ \"   \").width;\n"
    "\n"
    "		context.fillStyle = \'white\';\n"
    "		context.textAlign = \'right\';\n"
    "		var TextPosY = Y + YSpace;\n"
    "		DrawTextBox(context, fBegin.toFixed(2), X-3, TextPosY, \'right\');\n"
    "		var YS = [Y, YBottom];\n"
    "		for(var i = 0; i < YS.length; ++i)\n"
    "		{\n"
    "			var Y = YS[i];\n"
    "			var Y0 = Y + fRulerOffset;\n"
    "			var W0 = W - DurationWidth + FontWidth*1.5;\n"
    "			if(W0 > 6)\n"
    "			{\n"
    "				context.textAlign = \'center\';\n"
    "				DrawTextBox(context, Duration,Center * fScaleX, Y + YSpace, \'center\');\n"
    "				W0 = W0 / 2.0;\n"
    "				var X0 = X + W0;\n"
    "				var X1 = X + W - W0;\n"
    "				context.strokeStyle = ColorFront;\n"
    "				context.beginPath();\n"
    "				context.moveTo(X, Y0);\n"
    "				context.lineTo(X0, Y0);\n"
    "				context.moveTo(X0, Y0-2);\n"
    "				context.lineTo(X0, Y0+2);\n"
    "				context.moveTo(X1, Y0-2);\n"
    "				context.lineTo(X1, Y0+2);\n"
    "				context.moveTo(X1, Y0);\n"
    "				context.lineTo(X + W, Y0);\n"
    "				context.stroke();\n"
    "			}\n"
    "			else\n"
    "			{\n"
    "				if(i == 1)\n"
    "				{\n"
    "					context.textAlign = \'right\';\n"
    "					DrawTextBox(context, Duration, X - 3, Y0, \'right\');\n"
    "					context.textAlign = \'left\';\n"
    "					DrawTextBox(context, Duration, X + W + 2, Y0, \'left\');\n"
    "				}\n"
    "				context.strokeStyle = ColorFront;\n"
    "				context.beginPath();\n"
    "				context.moveTo(X, Y0);\n"
    "				context.lineTo(X+W, Y0);\n"
    "				context.stroke();\n"
    "			}\n"
    "		}\n"
    "		context.textAlign = \'left\';\n"
    "		DrawTextBox(context, fEnd.toFixed(2), X + W + 2, TextPosY, \'left\');\n"
    "		DrawTextBox(context, Name, X + W + 2, OffsetTop + YSpace + FontHeight, \'left\');\n"
    "	}\n"
    "	return 1;\n"
    "}\n"
    "\n"
    "function DrawDetailed(Animation)\n"
    "{\n"
    "	if(AnimationActive != Animation || !Initialized)\n"
    "	{\n"
    "		return;\n"
    "	}\n"
    "	ProfileEnter(\"DrawDetailed\");\n"
    "	DebugDrawQuadCount = 0;\n"
    "	DebugDrawTextCount = 0;\n"
    "	nHoverCSCpuNext = -1;\n"
    "\n"
    "	RangeCpuNext = RangeInit();\n"
    "	RangeGpuNext = RangeInit();\n"
    "	RangeGpu = RangeInit();\n"
    "\n"
    "	var start = new Date();\n"
    "	nDrawCount++;\n"
    "\n"
    "	var context = CanvasDetailedView.getContext(\'2d\');\n"
    "	var offscreen = CanvasDetailedOffscreen.getContext(\'2d\');\n"
    "	var fScaleX = nWidth / fDetailedRange; \n"
    "	var fOffsetY = -nOffsetY + BoxHeight;\n"
    "\n"
    "	if(DetailedRedrawState.fOffsetY == fOffsetY && DetailedRedrawState.fDetailedOffset == fDetailedOffset && "
    "DetailedRedrawState.fDetailedRange == fDetailedRange && !KeyCtrlDown && !KeyShiftDown && !MouseDragButton)\n"
    "	{\n"
    "		Invalidate++;\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		Invalidate = 0;\n"
    "		DetailedRedrawState.fOffsetY = fOffsetY;\n"
    "		DetailedRedrawState.fDetailedOffset = fDetailedOffset;\n"
    "		DetailedRedrawState.fDetailedRange = fDetailedRange;\n"
    "	}\n"
    "	if(nHoverTokenDrawn != nHoverToken)\n"
    "	{\n"
    "		Invalidate = 1;\n"
    "	}\n"
    "	nHoverTokenDrawn = nHoverToken;\n"
    "	if(Invalidate == 0) //when panning, only draw bars that are a certain width to keep decent framerate\n"
    "	{\n"
    "		context.clearRect(0, 0, CanvasDetailedView.width, CanvasDetailedView.height);\n"
    "		DrawDetailedView(context, nMinWidthPan, true);\n"
    "		ProfileRedraw0++;\n"
    "	}\n"
    "	else if(Invalidate == 1) //draw full and store\n"
    "	{\n"
    "		offscreen.clearRect(0, 0, CanvasDetailedView.width, CanvasDetailedView.height);\n"
    "		DrawDetailedView(offscreen, nMinWidth, true);\n"
    "		OffscreenData = offscreen.getImageData(0, 0, CanvasDetailedOffscreen.width, CanvasDetailedOffscreen.height);\n"
    "		ProfileRedraw1++;\n"
    "	}\n"
    "	else//reuse stored result untill next time viewport is changed.\n"
    "	{\n"
    "		context.clearRect(0, 0, CanvasDetailedView.width, CanvasDetailedView.height);\n"
    "		context.putImageData(OffscreenData, 0, 0);\n"
    "		DrawDetailedView(context, nMinWidth, false);\n"
    "		ProfileRedraw2++;\n"
    "	}\n"
    "\n"
    "	if(KeyShiftDown || KeyCtrlDown || MouseDragButton || MouseDragSelectRange() || ZoomActive)\n"
    "	{\n"
    "		nHoverToken = -1;\n"
    "		nHoverTokenIndex = -1;\n"
    "		nHoverTokenLogIndex = -1;\n"
    "		RangeCpu = RangeInit();\n"
    "		RangeGpu = RangeInit();\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		nHoverToken = nHoverTokenNext;\n"
    "		nHoverTokenIndex = nHoverTokenIndexNext;\n"
    "		nHoverTokenLogIndex = nHoverTokenLogIndexNext;\n"
    "		if(RangeValid(RangeCpuHistory))\n"
    "		{\n"
    "			RangeCopy(RangeCpu, RangeCpuHistory);\n"
    "			RangeCopy(RangeGpu, RangeGpuHistory);\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			RangeCopy(RangeCpu, RangeCpuNext);\n"
    "			RangeCopy(RangeGpu, RangeGpuNext);\n"
    "		}\n"
    "	}\n"
    "\n"
    "	DrawTextBox(context, TimeToMsString(fDetailedOffset), 0, FontHeight, \'left\');\n"
    "	context.textAlign = \'right\';\n"
    "	DrawTextBox(context, TimeToMsString(fDetailedOffset + fDetailedRange), nWidth, FontHeight, \'right\');\n"
    "	context.textAlign = \'left\';\n"
    "\n"
    "	var YBegin = ThreadY[fRangeThreadIdNext];\n"
    "	var YEnd = ThreadY[fRangeThreadIdNext+1];\n"
    "	var YBeginGpu = YBegin;\n"
    "	var YEndGpu = YEnd;\n"
    "	function RangeSet(R)\n"
    "	{\n"
    "		if(R.Thread >= 0)\n"
    "		{\n"
    "			R.YBegin = ThreadY[R.Thread];\n"
    "			R.YEnd = ThreadY[R.Thread + 1];\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			R.YBegin = 0;\n"
    "			R.YEnd = nHeight;\n"
    "		}\n"
    "	}\n"
    "	RangeSet(RangeSelect);\n"
    "	RangeSet(RangeCpu);\n"
    "	RangeSet(RangeGpu);\n"
    "	var Offset = 0;\n"
    "	Offset = DrawRange(context, RangeSelect, \'#59d0ff\', \'#00ddff\', \"Selection\");\n"
    "	Offset = DrawRange(context, RangeCpu, \'#009900\', \'#00ff00\', \"Cpu\");\n"
    "	Offset = DrawRange(context, RangeGpu, \'#996600\', \'#775500\', \"Gpu\");\n"
    "\n"
    "	nHoverCSCpu = nHoverCSCpuNext;\n"
    "	ProfileLeave();\n"
    "}\n"
    "function ZoomToHighlight(NoGpu)\n"
    "{\n"
    "	if(RangeValid(RangeGpu) && !NoGpu)\n"
    "	{\n"
    "		ZoomTo(RangeGpu.Begin, RangeGpu.End);\n"
    "	}\n"
    "	else if(RangeValid(RangeCpu))\n"
    "	{\n"
    "		ZoomTo(RangeCpu.Begin, RangeCpu.End);\n"
    "	}\n"
    "	RangeCpu = RangeInit();\n"
    "	RangeGpu = RangeInit();\n"
    "}\n"
    "\n"
    "function MoveToNext(Direction) //1 forward, -1 backwards\n"
    "{\n"
    "	var fTimeBegin, fTimeEnd, nLog;\n"
    "	var Index = nHoverToken;\n"
    "\n"
    "	if(nHoverToken != -1 && nHoverTokenLogIndex != -1)\n"
    "	{\n"
    "		fTimeBegin = RangeCpu.Begin;\n"
    "		fTimeEnd = RangeCpu.End;\n"
    "		nLog = nHoverTokenLogIndex;\n"
    "	}\n"
    "	else if(RangeValid(RangeSelect))\n"
    "	{\n"
    "		fTimeBegin = RangeSelect.Begin;\n"
    "		fTimeEnd = RangeSelect.End;\n"
    "		nLog = RangeSelect.Thread;\n"
    "		Index = RangeSelect.Index;\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		return;\n"
    "	}\n"
    "	if(nLog<0)\n"
    "	{\n"
    "		return;\n"
    "	}\n"
    "	var Forward = Direction && Direction < 0 ? 0 : 1;\n"
    "	var bFound = false;\n"
    "	var nStackPos = 0;\n"
    "	var fResultTimeBegin, fResultTimeEnd;\n"
    "	var TypeBegin = Forward ? 1 : 0;\n"
    "	var TypeEnd = Forward ? 0 : 1;\n"
    "	var SearchTimeBegin = Forward ? fTimeBegin : fTimeEnd;\n"
    "\n"
    "	var istart = Forward ? 0 : Frames.length-1;\n"
    "	var iend = Forward ? Frames.length : -1;\n"
    "	var idelta = Forward ? 1 : -1;\n"
    "	for(var i = istart; i != iend; i += idelta)\n"
    "	{\n"
    "		var fr = Frames[i];\n"
    "		var ts = fr.ts[nLog];\n"
    "		var ti = fr.ti[nLog];\n"
    "		var tt = fr.tt[nLog];\n"
    "		var jstart = Forward ? 0 : ts.length-1;\n"
    "		var jend = Forward ? ts.length : -1;\n"
    "		var jdelta = Forward ? 1 : -1;\n"
    "		for(var j = jstart; j != jend; j += jdelta)\n"
    "		{\n"
    "			if(!bFound)\n"
    "			{\n"
    "				if(tt[j] == TypeBegin && Index == ti[j])\n"
    "				{\n"
    "					if(SearchTimeBegin == ts[j])\n"
    "					{\n"
    "						bFound = true;\n"
    "					}\n"
    "				}\n"
    "			}\n"
    "			else\n"
    "			{\n"
    "				if(Index == ti[j])\n"
    "				{\n"
    "					var type = tt[j];\n"
    "					if(type == TypeBegin)\n"
    "					{\n"
    "						if(0 == nStackPos)\n"
    "						{\n"
    "							fResultTimeBegin = ts[j];\n"
    "						}\n"
    "						nStackPos++;\n"
    "					}\n"
    "					else if(type == TypeEnd && nStackPos)\n"
    "					{\n"
    "						nStackPos--;\n"
    "						if(0 == nStackPos)\n"
    "						{\n"
    "							fResultTimeEnd = ts[j];\n"
    "							if(0 == Forward)\n"
    "							{\n"
    "								var Tmp = fResultTimeBegin;\n"
    "								fResultTimeBegin = fResultTimeEnd;\n"
    "								fResultTimeEnd = Tmp;\n"
    "							}\n"
    "							RangeSelect.Begin = fResultTimeBegin;\n"
    "							RangeSelect.End = fResultTimeEnd;\n"
    "							RangeSelect.Thread = nLog;\n"
    "							RangeSelect.Index = Index;\n"
    "							MoveTo(fResultTimeBegin,fResultTimeEnd);\n"
    "							return;\n"
    "						}\n"
    "					}\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "}\n"
    "\n"
    "function MoveTo(fMoveBegin, fMoveEnd, YTop, YBottom)\n"
    "{\n"
    "	var nOffsetYBottom = YBottom - nHeight;\n"
    "	var nOffsetYDest = nOffsetY;\n"
    "	if(nOffsetYDest < nOffsetYBottom)\n"
    "	{\n"
    "		nOffsetYDest = nOffsetYBottom;\n"
    "	}\n"
    "	if(nOffsetYDest > YTop)\n"
    "	{\n"
    "		nOffsetYDest = YTop;\n"
    "	}\n"
    "	var fRange = fDetailedRange;\n"
    "	var fMinRange = (fMoveEnd-fMoveBegin) * 2.0;\n"
    "	if(fRange < fMinRange)\n"
    "	{\n"
    "		fRange = fMinRange;\n"
    "	}\n"
    "	var fMoveCenter = (fMoveBegin + fMoveEnd) * 0.5;\n"
    "	fMoveBegin = fMoveCenter - 0.5 * fRange;\n"
    "	fMoveEnd = fMoveCenter + 0.5 * fRange;\n"
    "	var nOffset;\n"
    "	if(nOffsetYDest != nOffsetY)\n"
    "		nOffset = nOffsetYDest;\n"
    "	ZoomTo(fMoveBegin, fMoveEnd, nOffsetYDest, -1);\n"
    "}\n"
    "function ZoomTo(fZoomBegin, fZoomEnd, OffsetYDest, ZoomTime)\n"
    "{\n"
    "	if(fZoomBegin < fZoomEnd)\n"
    "	{\n"
    "		AnimationActive = true;\n"
    "		var fDetailedOffsetOriginal = fDetailedOffset;\n"
    "		var fDetailedRangeOriginal = fDetailedRange;\n"
    "		var fDetailedOffsetTarget = fZoomBegin;\n"
    "		var fDetailedRangeTarget = fZoomEnd - fZoomBegin;\n"
    "		var OffsetYOriginal = nOffsetY;\n"
    "		var OffsetYTarget = OffsetYDest;\n"
    "		var TimestampStart = new Date();\n"
    "		var count = 0;\n"
    "		if(!ZoomTime)\n"
    "		{			\n"
    "			ZoomTime = ZOOM_TIME;\n"
    "		}\n"
    "\n"
    "		function ZoomFunc(Timestamp)\n"
    "		{\n"
    "			ZoomActive = 1;\n"
    "			var fPrc = (new Date() - TimestampStart) / (ZoomTime * 1000.0);\n"
    "			if(fPrc > 1.0 || ZoomTime < 0.01)\n"
    "			{\n"
    "				fPrc = 1.0;\n"
    "			}\n"
    "			fPrc = Math.pow(fPrc, 0.3);\n"
    "			fDetailedOffset = fDetailedOffsetOriginal + (fDetailedOffsetTarget - fDetailedOffsetOriginal) * fPrc;\n"
    "			fDetailedRange = fDetailedRangeOriginal + (fDetailedRangeTarget - fDetailedRangeOriginal) * fPrc;\n"
    "			if(OffsetYDest)\n"
    "			{\n"
    "				nOffsetY = OffsetYOriginal + (OffsetYTarget - OffsetYOriginal) * fPrc;\n"
    "			}\n"
    "			DrawDetailed(true);\n"
    "			if(fPrc >= 1.0)\n"
    "			{\n"
    "				AnimationActive = false;\n"
    "				fDetailedOffset = fDetailedOffsetTarget;\n"
    "				fDetailedRange = fDetailedRangeTarget;\n"
    "				if(OffsetYDest)\n"
    "				{\n"
    "					nOffsetY = OffsetYTarget;\n"
    "				}\n"
    "			}\n"
    "			else\n"
    "			{\n"
    "				requestAnimationFrame(ZoomFunc);\n"
    "			}\n"
    "		}\n"
    "		requestAnimationFrame(ZoomFunc);\n"
    "	}\n"
    "}\n"
    "function RequestRedraw()\n"
    "{\n"
    "	Invalidate = 0;\n"
    "	Draw(1);\n"
    "}\n"
    "function Draw(RedrawMode)\n"
    "{\n"
    "	if(ProfileMode)\n"
    "	{\n"
    "		ProfileModeClear();\n"
    "		ProfileEnter(\"Total\");\n"
    "	}\n"
    "	if(RedrawMode == 1)\n"
    "	{\n"
    "		if(Mode == ModeTimers)\n"
    "		{\n"
    "			DrawBarView();\n"
    "			DrawHoverToolTip();\n"
    "		}\n"
    "		else if(Mode == ModeDetailed)\n"
    "		{\n"
    "			DrawDetailed(false);\n"
    "			DrawHoverToolTip();\n"
    "		}\n"
    "		else if(Mode == ModeCounters)\n"
    "		{\n"
    "			DrawCounterView();\n"
    "			DrawHoverToolTip();\n"
    "		}\n"
    "	}\n"
    "	DrawDetailedFrameHistory();\n"
    "\n"
    "	if(ProfileMode)\n"
    "	{\n"
    "		ProfileLeave();\n"
    "		ProfileModeDraw(CanvasDetailedView);\n"
    "	}\n"
    "}\n"
    "\n"
    "function AutoRedraw(Timestamp)\n"
    "{\n"
    "	var RedrawMode = 0;\n"
    "	if(Mode == ModeDetailed)\n"
    "	{\n"
    "		if(ProfileMode == 2 || ((nHoverCSCpu >= 0 || nHoverToken != -1) && !KeyCtrlDown && !KeyShiftDown && "
    "!MouseDragButton)||(Invalidate<2 && !KeyCtrlDown && !KeyShiftDown && !MouseDragButton))\n"
    "		{\n"
    "			RedrawMode = 1;\n"
    "		}\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		if(Invalidate < 1)\n"
    "		{\n"
    "			RedrawMode = 1;\n"
    "		}\n"
    "	}\n"
    "	if(RedrawMode)\n"
    "	{\n"
    "		Draw(RedrawMode);\n"
    "	}\n"
    "	else if(FlashFrameCounter>0)\n"
    "	{\n"
    "		Draw(0);\n"
    "	}\n"
    "	requestAnimationFrame(AutoRedraw);\n"
    "}\n"
    "\n"
    "\n"
    "function ZoomGraph(nZoom)\n"
    "{\n"
    "	var fOldRange = fDetailedRange;\n"
    "	if(nZoom>0)\n"
    "	{\n"
    "		fDetailedRange *= Math.pow(nModDown ? 1.40 : 1.03, nZoom);\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		var fNewDetailedRange = fDetailedRange / Math.pow((nModDown ? 1.40 : 1.03), -nZoom);\n"
    "		if(fNewDetailedRange < 0.0001) //100ns\n"
    "			fNewDetailedRange = 0.0001;\n"
    "		fDetailedRange = fNewDetailedRange;\n"
    "	}\n"
    "\n"
    "	var fDiff = fOldRange - fDetailedRange;\n"
    "	var fMousePrc = DetailedViewMouseX / nWidth;\n"
    "	if(fMousePrc < 0)\n"
    "	{\n"
    "		fMousePrc = 0;\n"
    "	}\n"
    "	fDetailedOffset += fDiff * fMousePrc;\n"
    "\n"
    "}\n"
    "\n"
    "function MeasureFont()\n"
    "{\n"
    "	var context = CanvasDetailedView.getContext(\'2d\');\n"
    "	context.font = Font;\n"
    "	FontWidth = context.measureText(\'W\').width;\n"
    "\n"
    "}\n"
    "function ResizeCanvas() \n"
    "{\n"
    "	nWidth = window.innerWidth;\n"
    "	nHeight = window.innerHeight - CanvasHistory.height-2;\n"
    "	DPR = window.devicePixelRatio;\n"
    "\n"
    "	if(DPR)\n"
    "	{\n"
    "		CanvasDetailedView.style.width = nWidth + \'px\'; \n"
    "		CanvasDetailedView.style.height = nHeight + \'px\';\n"
    "		CanvasDetailedView.width = nWidth * DPR;\n"
    "		CanvasDetailedView.height = nHeight * DPR;\n"
    "		CanvasHistory.style.width = window.innerWidth + \'px\';\n"
    "		CanvasHistory.style.height = 70 + \'px\';\n"
    "		CanvasHistory.width = window.innerWidth * DPR;\n"
    "		CanvasHistory.height = 70 * DPR;\n"
    "		CanvasHistory.getContext(\'2d\').scale(DPR,DPR);\n"
    "		CanvasDetailedView.getContext(\'2d\').scale(DPR,DPR);\n"
    "\n"
    "		CanvasDetailedOffscreen.style.width = nWidth + \'px\';\n"
    "		CanvasDetailedOffscreen.style.height = nHeight + \'px\';\n"
    "		CanvasDetailedOffscreen.width = nWidth * DPR;\n"
    "		CanvasDetailedOffscreen.height = nHeight * DPR;\n"
    "		CanvasDetailedOffscreen.getContext(\'2d\').scale(DPR,DPR);\n"
    "\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		DPR = 1;\n"
    "		CanvasDetailedView.width = nWidth;\n"
    "		CanvasDetailedView.height = nHeight;\n"
    "		CanvasDetailedOffscreen.width = nWidth;\n"
    "		CanvasDetailedOffscreen.height = nHeight;\n"
    "		CanvasHistory.width = window.innerWidth;\n"
    "	}\n"
    "	RequestRedraw();\n"
    "}\n"
    "\n"
    "var MouseDragOff = 0;\n"
    "var MouseDragDown = 1;\n"
    "var MouseDragUp = 2;\n"
    "var MouseDragMove = 3;\n"
    "var MouseDragState = MouseDragOff;\n"
    "var MouseDragTarget = 0;\n"
    "var MouseDragButton = 0;\n"
    "var MouseDragKeyShift = 0;\n"
    "var MouseDragKeyCtrl = 0;\n"
    "var MouseDragX = 0;\n"
    "var MouseDragY = 0;\n"
    "var MouseDragXLast = 0;\n"
    "var MouseDragYLast = 0;\n"
    "var MouseDragXStart = 0;\n"
    "var MouseDragYStart = 0;\n"
    "\n"
    "function clamp(number, min, max)\n"
    "{\n"
    "  return Math.max(min, Math.min(number, max));\n"
    "}\n"
    "\n"
    "function MouseDragPan()\n"
    "{\n"
    "	return MouseDragButton == 1 || MouseDragKeyShift;\n"
    "}\n"
    "function MouseDragSelectRange()\n"
    "{\n"
    "	return MouseDragState == MouseDragMove && (MouseDragButton == 3 || (MouseDragKeyShift && MouseDragKeyCtrl));\n"
    "}\n"
    "function MouseHandleDrag()\n"
    "{\n"
    "	if(MouseDragTarget == CanvasDetailedView)\n"
    "	{\n"
    "		if(Mode == ModeDetailed)\n"
    "		{\n"
    "			if(MouseDragSelectRange())\n"
    "			{\n"
    "				var xStart = MouseDragXStart;\n"
    "				var xEnd = MouseDragX;\n"
    "				if(xStart > xEnd)\n"
    "				{\n"
    "					var Temp = xStart;\n"
    "					xStart = xEnd;\n"
    "					xEnd = Temp;\n"
    "				}\n"
    "				if(xEnd - xStart > 1)\n"
    "				{\n"
    "					RangeCpu.Begin = fDetailedOffset + fDetailedRange * (xStart / nWidth);\n"
    "					RangeCpu.End = fDetailedOffset + fDetailedRange * (xEnd / nWidth);\n"
    "					RangeSelect.Begin = fDetailedOffset + fDetailedRange * (xStart / nWidth);\n"
    "					RangeSelect.End = fDetailedOffset + fDetailedRange * (xEnd / nWidth);\n"
    "					RangeSelect.Thread = -1;\n"
    "					RangeSelect.Index = -1;\n"
    "				}\n"
    "			}\n"
    "			else if(MouseDragPan())\n"
    "			{\n"
    "				var X = MouseDragX - MouseDragXLast;\n"
    "				var Y = MouseDragY - MouseDragYLast;\n"
    "				if(X)\n"
    "				{\n"
    "					fDetailedOffset += -X * fDetailedRange / nWidth;\n"
    "				}\n"
    "				nOffsetY -= Y;\n"
    "				if(nOffsetY < 0)\n"
    "				{\n"
    "					nOffsetY = 0;\n"
    "				}\n"
    "			}\n"
    "			else if(MouseDragKeyCtrl)\n"
    "			{\n"
    "				if(MouseDragY != MouseDragYLast)\n"
    "				{\n"
    "					ZoomGraph(MouseDragY - MouseDragYLast);\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "		else if(Mode == ModeTimers)\n"
    "		{\n"
    "			if(MouseDragKeyShift || MouseDragButton == 1)\n"
    "			{\n"
    "				var X = MouseDragX - MouseDragXLast;\n"
    "				var Y = MouseDragY - MouseDragYLast;\n"
    "				nOffsetBarsY -= Y;\n"
    "				nOffsetBarsX -= X;\n"
    "				if(nOffsetBarsY < 0)\n"
    "				{\n"
    "					nOffsetBarsY = 0;\n"
    "				}\n"
    "				if(nOffsetBarsX < 0)\n"
    "				{\n"
    "					nOffsetBarsX = 0;\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "		else if(Mode == ModeCounters)\n"
    "		{\n"
    "			if(MouseDragKeyShift || MouseDragButton == 1)\n"
    "			{\n"
    "				var Y = MouseDragY - MouseDragYLast;\n"
    "				nOffsetCountersY -= Y;\n"
    "				if(nOffsetCountersY < 0)\n"
    "				{\n"
    "					nOffsetCountersY = 0;\n"
    "				}\n"
    "			}\n"
    "		}\n"
    "\n"
    "	}\n"
    "	else if(MouseDragTarget == CanvasHistory)\n"
    "	{\n"
    "		function HistoryFrameTime(x)\n"
    "		{\n"
    "			var NumFrames = Frames.length;\n"
    "			var fBarWidth = nWidth / NumFrames;\n"
    "			var Index = clamp(Math.floor(NumFrames * x / nWidth), 0, NumFrames-1);\n"
    "			var Lerp = clamp((x/fBarWidth - Index) , 0, 1);\n"
    "			var time = Frames[Index].framestart + (Frames[Index].frameend - Frames[Index].framestart) * Lerp;\n"
    "			return time;\n"
    "		}\n"
    "		if(MouseDragSelectRange())\n"
    "		{\n"
    "			RangeCpu = RangeInit();\n"
    "			RangeGpu = RangeInit();\n"
    "\n"
    "			var xStart = MouseDragXStart;\n"
    "			var xEnd = MouseDragX;\n"
    "			if(xStart > xEnd)\n"
    "			{\n"
    "				var Temp = xStart;\n"
    "				xStart = xEnd;\n"
    "				xEnd = Temp;\n"
    "			}\n"
    "			if(xEnd - xStart > 2)\n"
    "			{\n"
    "				var timestart = HistoryFrameTime(xStart);\n"
    "				var timeend = HistoryFrameTime(xEnd);\n"
    "				fDetailedOffset = timestart;\n"
    "				fDetailedRange = timeend-timestart;\n"
    "			}\n"
    "		}\n"
    "		else if(MouseDragPan())\n"
    "		{\n"
    "			var Time = HistoryFrameTime(MouseDragX);\n"
    "			fDetailedOffset = Time - fDetailedRange / 2.0;\n"
    "		}\n"
    "	}\n"
    "}\n"
    "function MouseHandleDragEnd()\n"
    "{\n"
    "	if(MouseDragTarget == CanvasDetailedView)\n"
    "	{\n"
    "\n"
    "	}\n"
    "	else if(MouseDragTarget == CanvasHistory)\n"
    "	{\n"
    "		if(!MouseDragSelectRange() && !MouseDragPan())\n"
    "		{\n"
    "			ZoomToHighlight(1);\n"
    "		}\n"
    "	}\n"
    "}\n"
    "\n"
    "function MouseHandleDragClick()\n"
    "{\n"
    "	if(MouseDragTarget == CanvasDetailedView)\n"
    "	{\n"
    "		if(Mode == ModeCounters)\n"
    "		{\n"
    "			if(nHoverCounter != -1)\n"
    "			{\n"
    "				if(CounterInfo[nHoverCounter].firstchild != -1)\n"
    "				{\n"
    "					CounterInfo[nHoverCounter].closed = !CounterInfo[nHoverCounter].closed;\n"
    "				}\n"
    "				else\n"
    "				{\n"
    "					CounterInfo[nHoverCounter].Expanded = !CounterInfo[nHoverCounter].Expanded;\n"
    "				}\n"
    "				Draw(1);\n"
    "			}\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			ZoomToHighlight();\n"
    "		}\n"
    "	}\n"
    "	else if(MouseDragTarget == CanvasHistory)\n"
    "	{\n"
    "		if(Mode == ModeDetailed)\n"
    "		{\n"
    "			ZoomToHighlight(1);\n"
    "		}\n"
    "	}\n"
    "}\n"
    "\n"
    "function MapMouseButton(event)\n"
    "{\n"
    "	if(event.button == 1 || event.which == 1)\n"
    "	{\n"
    "		return 1;\n"
    "	}\n"
    "	else if(event.button == 3 || event.which == 3)\n"
    "	{\n"
    "		return 3;\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		return 0;\n"
    "	}\n"
    "}\n"
    "\n"
    "function MouseDragReset()\n"
    "{\n"
    "	MouseDragState = MouseDragOff;\n"
    "	MouseDragTarget = 0;\n"
    "	MouseDragKeyShift = 0;\n"
    "	MouseDragKeyCtrl = 0;\n"
    "	MouseDragButton = 0;\n"
    "}\n"
    "function MouseDragKeyUp()\n"
    "{\n"
    "	if((MouseDragKeyShift && !KeyShiftDown) || (MouseDragKeyCtrl && !KeyCtrlDown))\n"
    "	{\n"
    "		MouseHandleDragEnd();\n"
    "		MouseDragReset();\n"
    "	}\n"
    "}\n"
    "function MouseDrag(Source, Event)\n"
    "{\n"
    "	if(Source == MouseDragOff || (MouseDragTarget && MouseDragTarget != Event.target))\n"
    "	{\n"
    "		MouseDragReset();\n"
    "		return;\n"
    "	}\n"
    "\n"
    "	var LocalRect = Event.target.getBoundingClientRect();\n"
    "	MouseDragX = Event.clientX - LocalRect.left;\n"
    "	MouseDragY = Event.clientY - LocalRect.top;\n"
    "	if(MouseDragState == MouseDragMove)\n"
    "	{\n"
    "		var dx = Math.abs(MouseDragX - MouseDragXStart);\n"
    "		var dy = Math.abs(MouseDragY - MouseDragYStart);\n"
    "		if((Source == MouseDragUp && MapMouseButton(Event) == MouseDragButton) ||\n"
    "			(MouseDragKeyCtrl && !KeyCtrlDown) ||\n"
    "			(MouseDragKeyShift && !KeyShiftDown))\n"
    "		{\n"
    "			MouseHandleDragEnd();\n"
    "			MouseDragReset();\n"
    "			return;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			MouseHandleDrag();\n"
    "		}\n"
    "	}\n"
    "	else if(MouseDragState == MouseDragOff)\n"
    "	{\n"
    "		if(Source == MouseDragDown || KeyShiftDown || KeyCtrlDown)\n"
    "		{\n"
    "			MouseDragTarget = Event.target;\n"
    "			MouseDragButton = MapMouseButton(Event);\n"
    "			MouseDragState = MouseDragDown;\n"
    "			MouseDragXStart = MouseDragX;\n"
    "			MouseDragYStart = MouseDragY;\n"
    "			MouseDragKeyCtrl = 0;\n"
    "			MouseDragKeyShift = 0;\n"
    "\n"
    "			if(KeyShiftDown || KeyCtrlDown)\n"
    "			{\n"
    "				MouseDragKeyShift = KeyShiftDown;\n"
    "				MouseDragKeyCtrl = KeyCtrlDown;\n"
    "				MouseDragState = MouseDragMove;\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "	else if(MouseDragState == MouseDragDown)\n"
    "	{\n"
    "		if(Source == MouseDragUp)\n"
    "		{\n"
    "			MouseHandleDragClick();\n"
    "			MouseDragReset();\n"
    "		}\n"
    "		else if(Source == MouseDragMove)\n"
    "		{\n"
    "			var dx = Math.abs(MouseDragX - MouseDragXStart);\n"
    "			var dy = Math.abs(MouseDragY - MouseDragYStart);\n"
    "			if(dx+dy>1)\n"
    "			{\n"
    "				MouseDragState = MouseDragMove;\n"
    "			}\n"
    "		}\n"
    "	}\n"
    "	MouseDragXLast = MouseDragX;\n"
    "	MouseDragYLast = MouseDragY;\n"
    "}\n"
    "\n"
    "function MouseMove(evt)\n"
    "{\n"
    "    evt.preventDefault();\n"
    "    ZoomActive = 0;\n"
    "    MouseDrag(MouseDragMove, evt);\n"
    " 	MouseHistory = 0;\n"
    "	MouseDetailed = 0;\n"
    "	HistoryViewMouseX = HistoryViewMouseY = -1;\n"
    "	var rect = evt.target.getBoundingClientRect();\n"
    "	var x = evt.clientX - rect.left;\n"
    "	var y = evt.clientY - rect.top;\n"
    "	if(evt.target == CanvasDetailedView)\n"
    "	{\n"
    "		if(!MouseDragSelectRange())\n"
    "		{\n"
    "			RangeCpu = RangeInit();\n"
    "		}\n"
    "		DetailedViewMouseX = x;\n"
    "		DetailedViewMouseY = y;\n"
    "	}\n"
    "	else if(evt.target = CanvasHistory)\n"
    "	{\n"
    "		var Rect = CanvasHistory.getBoundingClientRect();\n"
    "		HistoryViewMouseX = x;\n"
    "		HistoryViewMouseY = y;\n"
    "	}\n"
    "	Draw(1);\n"
    "}\n"
    "\n"
    "function MouseButton(bPressed, evt)\n"
    "{\n"
    "    evt.preventDefault();\n"
    "	MouseDrag(bPressed ? MouseDragDown : MouseDragUp, evt);\n"
    "	if(!bPressed)\n"
    "	{\n"
    "		if(SortColumnMouseOverNext)\n"
    "		{\n"
    "			if(SortColumnMouseOverNext == SortColumnMouseOver)\n"
    "			{\n"
    "				SortColumnOrderFlip =  1 - SortColumnOrderFlip;\n"
    "			}\n"
    "			else\n"
    "			{\n"
    "				SortColumnOrderFlip = 0;\n"
    "			}\n"
    "\n"
    "			SortColumnMouseOver = SortColumnMouseOverNext;\n"
    "			SortColumnMouseOverNext = null;\n"
    "			if(SortColumnMouseOver == StrAverage)\n"
    "			{\n"
    "				SortColumn = 1;\n"
    "			}\n"
    "			else if(SortColumnMouseOver == StrMax)\n"
    "			{\n"
    "				SortColumn = 2;\n"
    "			}\n"
    "			else if(SortColumnMouseOver == StrTotal)\n"
    "			{\n"
    "				SortColumn = 3;\n"
    "			}\n"
    "			else if(SortColumnMouseOver == StrMin)\n"
    "			{\n"
    "				SortColumn = 4;\n"
    "			}\n"
    "			else if(SortColumnMouseOver == StrCallAverage)\n"
    "			{\n"
    "				SortColumn = 5;\n"
    "			}\n"
    "			else if(SortColumnMouseOver == StrCount)\n"
    "			{\n"
    "				SortColumn = 6;\n"
    "			}\n"
    "			else if(SortColumnMouseOver == StrExclAverage)\n"
    "			{\n"
    "				SortColumn = 7;\n"
    "			}\n"
    "			else if(SortColumnMouseOver == StrExclMax)\n"
    "			{\n"
    "				SortColumn = 8;\n"
    "			}\n"
    "			else if(SortColumnMouseOver == StrGroup)\n"
    "			{\n"
    "				SortColumn = 0;\n"
    "			}\n"
    "			RequestRedraw();\n"
    "		}\n"
    "	}\n"
    "}\n"
    "\n"
    "function MouseOut(evt)\n"
    "{\n"
    "	MouseDrag(MouseDragOff, evt);\n"
    "	KeyCtrlDown = 0;\n"
    "	KeyShiftDown = 0;\n"
    "	MouseDragButton = 0;\n"
    "	nHoverToken = -1;\n"
    "	RangeCpu = RangeInit();\n"
    "}\n"
    "\n"
    "function MouseWheel(e)\n"
    "{\n"
    "    var e = window.event || e;\n"
    "    var delta = (e.wheelDelta || e.detail * (-120));\n"
    "    ZoomGraph((-4 * delta / 120.0) | 0);\n"
    "    Draw(1);\n"
    "}\n"
    "function ShowFilterInput(bShow)\n"
    "{\n"
    "	if(bShow)\n"
    "	{\n"
    "		document.getElementById(\'filterinput\').style[\'display\'] = \'block\';\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		document.getElementById(\'filterinput\').style[\'display\'] = \'none\';\n"
    "	}\n"
    "}\n"
    "\n"
    "function SetFilterInput(group, timer)\n"
    "{\n"
    "	FilterInputGroupString = group;\n"
    "	FilterInputTimerString = timer;\n"
    "	FilterInputGroup.value = group?group:\'\';\n"
    "	FilterInputTimer.value = timer?timer:\'\';\n"
    "	FilterUpdate();\n"
    "	if(group || timer)\n"
    "	{\n"
    "		ShowFilterInput(1);\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		ShowFilterInput(0);\n"
    "	}\n"
    "\n"
    "}\n"
    "\n"
    "function ToggleFilterInput(escape)\n"
    "{\n"
    "	var ActiveElement = -1;\n"
    "	for(var i = 0; i < FilterInputArray.length; ++i)\n"
    "	{\n"
    "		if(FilterInputArray[i] == document.activeElement)\n"
    "		{\n"
    "			ActiveElement = i;\n"
    "		}\n"
    "	}\n"
    "	var OldActiveElement = ActiveElement;\n"
    "	if(ActiveElement >= 0)\n"
    "	{\n"
    "		FilterInputArray[ActiveElement].blur();\n"
    "	}\n"
    "	ActiveElement++;\n"
    "	if(!escape)\n"
    "	{\n"
    "		if(ActiveElement < FilterInputArray.length)\n"
    "		{\n"
    "			ShowFilterInput(1);\n"
    "			FilterInputArray[ActiveElement].focus();\n"
    "		}\n"
    "	}\n"
    "	else\n"
    "	{\n"
    "		if(-1 == OldActiveElement)\n"
    "		{\n"
    "			SetFilterInput();\n"
    "		}\n"
    "	}\n"
    "}\n"
    "\n"
    "function KeyUp(evt)\n"
    "{\n"
    "	if(evt.keyCode == 39)\n"
    "	{\n"
    "		MoveToNext(1);\n"
    "	}\n"
    "	if(evt.keyCode == 37)\n"
    "	{\n"
    "		MoveToNext(-1);\n"
    "	}\n"
    "	if(evt.keyCode == 17)\n"
    "	{\n"
    "		KeyCtrlDown = 0;\n"
    "		MouseDragKeyUp();\n"
    "	}\n"
    "	else if(evt.keyCode == 16)\n"
    "	{\n"
    "		KeyShiftDown = 0;\n"
    "		MouseDragKeyUp();\n"
    "	}\n"
    "	if(evt.keyCode == 32)\n"
    "	{\n"
    "		if(RangeSelect.Begin < RangeSelect.End)\n"
    "		{\n"
    "			ZoomTo(RangeSelect.Begin, RangeSelect.End);\n"
    "			RangeSelect = RangeInit();\n"
    "			MouseHandleDragEnd();\n"
    "		}\n"
    "	}\n"
    "	if(evt.keyCode == 9)\n"
    "	{\n"
    "		evt.preventDefault();\n"
    "		if(Mode == ModeDetailed)\n"
    "		{\n"
    "			var Token = nHoverToken;\n"
    "			if(Token == -1 && RangeValid(RangeSelect) && RangeSelect.Index >= 0)\n"
    "			{\n"
    "				Token = RangeSelect.Index;\n"
    "			}\n"
    "			if(Token != -1 && Token < TimerInfo.length)\n"
    "			{\n"
    "				var start = TimerInfo[Token].worststart;\n"
    "				var end = TimerInfo[Token].worstend;\n"
    "				RangeSelect.Begin = start;\n"
    "				RangeSelect.End = end;\n"
    "				RangeSelect.Thread = TimerInfo[Token].worstthread;\n"
    "				RangeSelect.Index = Token;\n"
    "				ShowFlashMessage(\'Worst: \' + (end-start).toFixed(2) + \'ms\', 100);\n"
    "				MoveTo(RangeSelect.Begin, RangeSelect.End, ThreadY[RangeSelect.Thread] + nOffsetY, ThreadY[RangeSelect.Thread+1] + "
    "nOffsetY);\n"
    "				MouseHandleDragEnd();\n"
    "			}\n"
    "		}\n"
    "		else if(Mode == ModeTimers)\n"
    "		{\n"
    "			ToggleFilterInput(0);\n"
    "			evt.preventDefault();\n"
    "		}\n"
    "\n"
    "	}\n"
    "	if(evt.keyCode == 27)\n"
    "	{\n"
    "		RangeSelect = RangeInit();\n"
    "		SortColumn = 0;\n"
    "		SortColumnMouseOver = \"\";\n"
    "		if(Mode == ModeTimers)\n"
    "		{\n"
    "			ToggleFilterInput(1);\n"
    "			evt.preventDefault();\n"
    "		}\n"
    "	}\n"
    "\n"
    "	if(evt.keyCode == 18 || evt.keyCode == 90) // z/tab to toggle tooltip\n"
    "	{\n"
    "		ToolTip = (ToolTip+1)%3; //0: off, 1: default, 2: flipped\n"
    "		var ToolTipStr = \'Off\';\n"
    "		var bShowTimers = Mode == ModeTimers;\n"
    "		if(ToolTip == 2)\n"
    "		{\n"
    "			bShowTimers = !bShowTimers;\n"
    "		}\n"
    "		if(ToolTip)\n"
    "		{\n"
    "			if(bShowTimers)\n"
    "				ToolTipStr = \"Timers\";\n"
    "			else\n"
    "				ToolTipStr = \"Detailed\";\n"
    "		}\n"
    "		ShowFlashMessage(\'ToolTip: \' + ToolTipStr, 100);\n"
    "	}\n"
    "\n"
    "\n"
    "	Invalidate = 0;\n"
    "}\n"
    "function CreateFilter(Filter)\n"
    "{\n"
    "	if(!Filter || Filter.length == 0)\n"
    "	{\n"
    "		return null;\n"
    "	}\n"
    "	Filter = Filter.split(\' \');\n"
    "	for(var i = 0; i < Filter.length; ++i)\n"
    "	{\n"
    "		Filter[i] = new RegExp(Filter[i], \"i\");\n"
    "	}\n"
    "	return Filter;\n"
    "}\n"
    "function FilterKeyUp()\n"
    "{\n"
    "	FilterInputTimerString = FilterInputTimer.value;\n"
    "	FilterInputGroupString = FilterInputGroup.value;\n"
    "	FilterUpdate();\n"
    "}\n"
    "\n"
    "function FilterUpdate()\n"
    "{\n"
    "	FilterTimer = CreateFilter(FilterInputTimerString);\n"
    "	FilterGroup = CreateFilter(FilterInputGroupString);\n"
    "}\n"
    "\n"
    "function KeyDown(evt)\n"
    "{\n"
    "	if(evt.keyCode == 17)\n"
    "	{\n"
    "		KeyCtrlDown = 1;\n"
    "	}\n"
    "	else if(evt.keyCode == 16)\n"
    "	{\n"
    "		KeyShiftDown = 1;\n"
    "	}\n"
    "	else if(evt.keyCode == 9)\n"
    "	{\n"
    "		evt.preventDefault();\n"
    "	}\n"
    "	Invalidate = 0;\n"
    "}\n"
    "\n"
    "function ReadCookie()\n"
    "{\n"
    "	var result = document.cookie.match(/fisk=([^;]+)/);\n"
    "	var NewMode = ModeTimers;\n"
    "	var ReferenceTimeString = \'33ms\';\n"
    "	if(result && result.length > 0)\n"
    "	{\n"
    "		var Obj = JSON.parse(result[1]);\n"
    "		if(Obj.Mode)\n"
    "		{\n"
    "			NewMode = Obj.Mode;\n"
    "		}\n"
    "		if(Obj.ReferenceTime)\n"
    "		{\n"
    "			ReferenceTimeString = Obj.ReferenceTime;\n"
    "		}\n"
    "		if(Obj.ThreadsAllActive || Obj.ThreadsAllActive == 0 || Obj.ThreadsAllActive == false)\n"
    "		{\n"
    "			ThreadsAllActive = Obj.ThreadsAllActive;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			ThreadsAllActive = 1;\n"
    "		}\n"
    "		if(Obj.ThreadsActive)\n"
    "		{\n"
    "			ThreadsActive = Obj.ThreadsActive;\n"
    "		}\n"
    "		if(Obj.GroupsAllActive || Obj.GroupsAllActive == 0 || Obj.GroupsAllActive)\n"
    "		{\n"
    "			GroupsAllActive = Obj.GroupsAllActive;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			GroupsAllActive = 1;\n"
    "		}\n"
    "		if(Obj.GroupsActive)\n"
    "		{\n"
    "			GroupsActive = Obj.GroupsActive;\n"
    "		}\n"
    "		if(Obj.nContextSwitchEnabled)\n"
    "		{\n"
    "			nContextSwitchEnabled = Obj.nContextSwitchEnabled; \n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			nContextSwitchEnabled = 1;\n"
    "		}\n"
    "		if(Obj.GroupColors)\n"
    "		{\n"
    "			GroupColors = Obj.GroupColors;\n"
    "		}\n"
    "		else\n"
    "		{\n"
    "			GroupColors = 0;\n"
    "		}\n"
    "		if(Obj.nHideHelp)\n"
    "		{\n"
    "			nHideHelp = 1;\n"
    "		}\n"
    "		TimersGroups = Obj.TimersGroups?Obj.TimersGroups:0;\n"
    "		TimersMeta = Obj.TimersMeta?0:1;\n"
    "	}\n"
    "	SetContextSwitch(nContextSwitchEnabled);\n"
    "	SetMode(NewMode, TimersGroups);\n"
    "	SetReferenceTime(ReferenceTimeString);\n"
    "	UpdateOptionsMenu();\n"
    "	UpdateGroupColors();\n"
    "}\n"
    "function WriteCookie()\n"
    "{\n"
    "	var Obj = new Object();\n"
    "	Obj.Mode = Mode;\n"
    "	Obj.ReferenceTime = ReferenceTime + \'ms\';\n"
    "	Obj.ThreadsActive = ThreadsActive;\n"
    "	Obj.ThreadsAllActive = ThreadsAllActive;\n"
    "	Obj.GroupsActive = GroupsActive;\n"
    "	Obj.GroupsAllActive = GroupsAllActive;\n"
    "	Obj.nContextSwitchEnabled = nContextSwitchEnabled;\n"
    "	Obj.TimersGroups = TimersGroups?TimersGroups:0;\n"
    "	Obj.TimersMeta = TimersMeta?0:1;\n"
    "	Obj.GroupColors = GroupColors;\n"
    "	if(nHideHelp)\n"
    "	{\n"
    "		Obj.nHideHelp = 1;\n"
    "	}\n"
    "	var date = new Date();\n"
    "	date.setFullYear(2099);\n"
    "	var cookie = \'fisk=\' + JSON.stringify(Obj) + \';expires=\' + date;\n"
    "	document.cookie = cookie;\n"
    "}\n"
    "\n"
    "var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? \"DOMMouseScroll\" : \"mousewheel\" //FF doesn\'t recogniz";

const size_t g_ProfileHtml_end_2_size = sizeof(g_ProfileHtml_end_2);
const char   g_ProfileHtml_end_3[] = "e mousewheel as of FF3.x\n"
                                   "\n"
                                   "CanvasDetailedView.addEventListener(\'mousemove\', MouseMove, false);\n"
                                   "CanvasDetailedView.addEventListener(\'mousedown\', function(evt) { MouseButton(true, evt); });\n"
                                   "CanvasDetailedView.addEventListener(\'mouseup\', function(evt) { MouseButton(false, evt); } );\n"
                                   "CanvasDetailedView.addEventListener(\'mouseout\', MouseOut);\n"
                                   "CanvasDetailedView.addEventListener(\"contextmenu\", function (e) { e.preventDefault(); }, false);\n"
                                   "CanvasDetailedView.addEventListener(mousewheelevt, MouseWheel, false);\n"
                                   "CanvasHistory.addEventListener(\'mousemove\', MouseMove);\n"
                                   "CanvasHistory.addEventListener(\'mousedown\', function(evt) { MouseButton(true, evt); });\n"
                                   "CanvasHistory.addEventListener(\'mouseup\', function(evt) { MouseButton(false, evt); } );\n"
                                   "CanvasHistory.addEventListener(\'mouseout\', MouseOut);\n"
                                   "CanvasHistory.addEventListener(\"contextmenu\", function (e) { e.preventDefault(); }, false);\n"
                                   "CanvasHistory.addEventListener(mousewheelevt, MouseWheel, false);\n"
                                   "FilterInputTimer.addEventListener(\'keyup\', FilterKeyUp);\n"
                                   "FilterInputGroup.addEventListener(\'keyup\', FilterKeyUp);\n"
                                   "window.addEventListener(\'keydown\', KeyDown);\n"
                                   "window.addEventListener(\'keyup\', KeyUp);\n"
                                   "window.addEventListener(\'resize\', ResizeCanvas, false);\n"
                                   "\n"
                                   "\n"
                                   "\n"
                                   "\n"
                                   "function CalcAverage()\n"
                                   "{\n"
                                   "	var Sum = 0;\n"
                                   "	var Count = 0;\n"
                                   "	for(nLog = 0; nLog < nNumLogs; nLog++)\n"
                                   "	{\n"
                                   "		StackPos = 0;\n"
                                   "		for(var i = 0; i < Frames.length; i++)\n"
                                   "		{\n"
                                   "			var Frame_ = Frames[i];			\n"
                                   "			var tt = Frame_.tt[nLog];\n"
                                   "			var ts = Frame_.ts[nLog];\n"
                                   "\n"
                                   "			var count = tt.length;\n"
                                   "			for(var j = 0; j < count; j++)\n"
                                   "			{\n"
                                   "				var type = tt[j];\n"
                                   "				var time = ts[j];\n"
                                   "				if(type == 1)\n"
                                   "				{\n"
                                   "					Stack[StackPos] = time;//store the frame which it comes from\n"
                                   "					StackPos++;\n"
                                   "				}\n"
                                   "				else if(type == 0)\n"
                                   "				{\n"
                                   "					if(StackPos>0)\n"
                                   "					{\n"
                                   "\n"
                                   "						StackPos--;\n"
                                   "						var localtime = time - Stack[StackPos];\n"
                                   "						Count++;\n"
                                   "						Sum += localtime;\n"
                                   "					}\n"
                                   "				}\n"
                                   "			}\n"
                                   "		}\n"
                                   "	}\n"
                                   "	return Sum / Count;\n"
                                   "\n"
                                   "}\n"
                                   "\n"
                                   "function MakeLod(index, MinDelta, GlobalArray, LogStart)\n"
                                   "{\n"
                                   "	if(LodData[index])\n"
                                   "	{\n"
                                   "		console.log(\"error!!\");\n"
                                   "	}\n"
                                   "	var o = new Object();\n"
                                   "	o.MinDelta = MinDelta;\n"
                                   "	o.GlobalArray = GlobalArray;\n"
                                   "	o.LogStart = LogStart;\n"
                                   "	LodData[index] = o;\n"
                                   "}\n"
                                   "\n"
                                   "function PreprocessBuildSplitArray()\n"
                                   "{\n"
                                   "	var nNumLogs = Frames[0].ts.length;\n"
                                   "\n"
                                   "	ProfileEnter(\"PreprocessBuildSplitArray\");\n"
                                   "	var SplitArrays = new Array(nNumLogs);\n"
                                   "\n"
                                   "	for(nLog = 0; nLog < nNumLogs; nLog++)\n"
                                   "	{\n"
                                   "		var MaxDepth = 1;\n"
                                   "		var StackPos = 0;\n"
                                   "		var Stack = Array(20);\n"
                                   "		var TypeArray = g_TypeArray[nLog];\n"
                                   "		var TimeArray = g_TimeArray[nLog];\n"
                                   "		var DeltaTimes = new Array(TypeArray.length);\n"
                                   "\n"
                                   "		for(var j = 0; j < TypeArray.length; ++j)\n"
                                   "		{\n"
                                   "			var type = TypeArray[j];\n"
                                   "			var time = TimeArray[j];\n"
                                   "			if(type == 1)\n"
                                   "			{\n"
                                   "				//push\n"
                                   "				Stack[StackPos] = time;\n"
                                   "				StackPos++;\n"
                                   "			}\n"
                                   "			else if(type == 0)\n"
                                   "			{\n"
                                   "				if(StackPos>0)\n"
                                   "				{\n"
                                   "					StackPos--;\n"
                                   "					DeltaTimes[j] = time - Stack[StackPos];\n"
                                   "				}\n"
                                   "				else\n"
                                   "				{\n"
                                   "					DeltaTimes[j] = 0;\n"
                                   "				}\n"
                                   "			}\n"
                                   "		}\n"
                                   "		DeltaTimes.sort(function(a,b){return b-a;});\n"
                                   "		var SplitArray = Array(NumLodSplits);\n"
                                   "		var SplitIndex = DeltaTimes.length;\n"
                                   "\n"
                                   "		var j = 0;\n"
                                   "		for(j = 0; j < NumLodSplits; ++j)\n"
                                   "		{\n"
                                   "			SplitIndex = Math.floor(SplitIndex / 2);\n"
                                   "			while(SplitIndex > 0 && !DeltaTimes[SplitIndex])\n"
                                   "			{\n"
                                   "				SplitIndex--;\n"
                                   "			}\n"
                                   "			if(SplitIndex < SplitMin)\n"
                                   "			{\n"
                                   "				break;\n"
                                   "			}\n"
                                   "			//search.. if 0\n"
                                   "			var SplitTime = DeltaTimes[SplitIndex];\n"
                                   "			if(SplitTime>=0)\n"
                                   "			{\n"
                                   "				SplitArray[j] = SplitTime;\n"
                                   "			}\n"
                                   "			else\n"
                                   "			{\n"
                                   "				SplitArray[j] = SPLIT_LIMIT;\n"
                                   "			}\n"
                                   "			if(j>0)\n"
                                   "			{\n"
                                   "				console.assert(SplitArray[j-1] <= SplitArray[j], \"must be less\");\n"
                                   "			}\n"
                                   "\n"
                                   "		}\n"
                                   "		for(; j < NumLodSplits; ++j)\n"
                                   "		{\n"
                                   "			SplitArray[j] = SPLIT_LIMIT;\n"
                                   "		}\n"
                                   "\n"
                                   "\n"
                                   "		SplitArrays[nLog] = SplitArray;\n"
                                   "	}\n"
                                   "	ProfileLeave();\n"
                                   "	return SplitArrays;\n"
                                   "}\n"
                                   "\n"
                                   "function PreprocessBuildDurationArray()\n"
                                   "{\n"
                                   "	var nNumLogs = Frames[0].ts.length;\n"
                                   "	ProfileEnter(\"PreprocessBuildDurationArray\");\n"
                                   "	var DurationArrays = new Array(nNumLogs);\n"
                                   "	for(nLog = 0; nLog < nNumLogs; ++nLog)\n"
                                   "	{\n"
                                   "		var MaxDepth = 1;\n"
                                   "		var StackPos = 0;\n"
                                   "		var Stack = Array(20);\n"
                                   "		var StackIndex = Array(20);\n"
                                   "		var TypeArray = g_TypeArray[nLog];\n"
                                   "		var TimeArray = g_TimeArray[nLog];\n"
                                   "		var DurationArray = Array(g_TypeArray[nLog].length);\n"
                                   "		for(var j = 0; j < TypeArray.length; ++j)\n"
                                   "		{\n"
                                   "			var type = TypeArray[j];\n"
                                   "			var time = TimeArray[j];\n"
                                   "			if(type == 1)\n"
                                   "			{\n"
                                   "				//push\n"
                                   "				Stack[StackPos] = time;\n"
                                   "				StackIndex[StackPos] = j;\n"
                                   "				StackPos++;\n"
                                   "			}\n"
                                   "			else if(type == 0)\n"
                                   "			{\n"
                                   "				if(StackPos>0)\n"
                                   "				{\n"
                                   "					StackPos--;\n"
                                   "					var Duration = time - Stack[StackPos];\n"
                                   "					DurationArray[StackIndex[StackPos]] = Duration;\n"
                                   "					DurationArray[j] = Duration;\n"
                                   "				}\n"
                                   "				else\n"
                                   "				{\n"
                                   "					DurationArray[j] = 0;\n"
                                   "				}\n"
                                   "			}\n"
                                   "		}\n"
                                   "		for(var j = 0; j < StackPos; ++j)\n"
                                   "		{\n"
                                   "			DurationArray[j] = 0;\n"
                                   "		}\n"
                                   "		DurationArrays[nLog] = DurationArray;\n"
                                   "	}\n"
                                   "	ProfileLeave();\n"
                                   "	return DurationArrays;\n"
                                   "\n"
                                   "}\n"
                                   "function PreprocessLods()\n"
                                   "{\n"
                                   "	ProfileEnter(\"PreprocessLods\");\n"
                                   "	var nNumLogs = Frames[0].ts.length;\n"
                                   "	var SplitArrays = PreprocessBuildSplitArray();\n"
                                   "	var DurationArrays = PreprocessBuildDurationArray();\n"
                                   "	var Source = LodData[0];\n"
                                   "	var SourceLogStart = Source.LogStart;\n"
                                   "	var NumFrames = SourceLogStart.length;\n"
                                   "\n"
                                   "	for(var i = 0; i < NumLodSplits-1; ++i)\n"
                                   "	{\n"
                                   "		var DestLogStart = Array(SourceLogStart.length);\n"
                                   "		for(var j = 0; j < DestLogStart.length; ++j)\n"
                                   "		{\n"
                                   "			DestLogStart[j] = Array(nNumLogs);\n"
                                   "		}\n"
                                   "		var MinDelta = Array(nNumLogs);\n"
                                   "		var GlobalArray = Array(nNumLogs);\n"
                                   "\n"
                                   "		for(nLog = 0; nLog < nNumLogs; ++nLog)\n"
                                   "		{\n"
                                   "			var Duration = DurationArrays[nLog];\n"
                                   "			var SplitTime = SplitArrays[nLog][i];\n"
                                   "\n"
                                   "			MinDelta[nLog] = SplitTime;\n"
                                   "			if(SplitTime < SPLIT_LIMIT)\n"
                                   "			{\n"
                                   "				var SourceCount = Duration.length;\n"
                                   "				var DestGlobalArray = Array();\n"
                                   "				var RemapArray = Array(SourceCount);\n"
                                   "\n"
                                   "				for(var j = 0; j < SourceCount; ++j)\n"
                                   "				{\n"
                                   "					RemapArray[j] = DestGlobalArray.length;\n"
                                   "					if(Duration[j] >= SplitTime)\n"
                                   "					{\n"
                                   "						DestGlobalArray.push(j);\n"
                                   "					}\n"
                                   "				}\n"
                                   "				GlobalArray[nLog] = DestGlobalArray;\n"
                                   "				for(var j = 0; j < NumFrames; ++j)\n"
                                   "				{\n"
                                   "					var OldStart = SourceLogStart[j][nLog];\n"
                                   "					var NewStart = RemapArray[OldStart];\n"
                                   "					var FrameArray = DestLogStart[j];\n"
                                   "					FrameArray[nLog] = NewStart;\n"
                                   "				}\n"
                                   "			}\n"
                                   "			else\n"
                                   "			{\n"
                                   "\n"
                                   "				for(var j = 0; j < NumFrames; ++j)\n"
                                   "				{\n"
                                   "					var FrameArray = DestLogStart[j];\n"
                                   "	\n"
                                   "					FrameArray[nLog] = 0;\n"
                                   "				}\n"
                                   "\n"
                                   "			}\n"
                                   "\n"
                                   "		}\n"
                                   "		MakeLod(i+1, MinDelta, GlobalArray, DestLogStart);\n"
                                   "	}\n"
                                   "	ProfileLeave();\n"
                                   "}\n"
                                   "function PreprocessGlobalArray()\n"
                                   "{\n"
                                   "	ProfileEnter(\"PreprocessGlobalArray\");\n"
                                   "	var nNumLogs = Frames[0].ts.length;\n"
                                   "	var CaptureStart = Frames[0].framestart;\n"
                                   "	var CaptureEnd = Frames[Frames.length-1].frameend;\n"
                                   "	g_GlobalArray = new Array(nNumLogs);\n"
                                   "	g_TypeArray = new Array(nNumLogs);\n"
                                   "	g_TimeArray = new Array(nNumLogs);\n"
                                   "	g_IndexArray = new Array(nNumLogs);\n"
                                   "	g_LabelArray = new Array(nNumLogs);\n"
                                   "	var StackPos = 0;\n"
                                   "	var Stack = Array(20);\n"
                                   "	var LogStartArray = new Array(Frames.length);\n"
                                   "	for(var i = 0; i < Frames.length; i++)\n"
                                   "	{\n"
                                   "		Frames[i].LogStart = new Array(nNumLogs);	\n"
                                   "		LogStartArray[i] = Frames[i].LogStart;\n"
                                   "\n"
                                   "		Frames[i].LogEnd = new Array(nNumLogs);\n"
                                   "	}\n"
                                   "	var MinDelta = Array(nNumLogs);\n"
                                   "	for(nLog = 0; nLog < nNumLogs; nLog++)\n"
                                   "	{\n"
                                   "		MinDelta[nLog] = 0;\n"
                                   "		var Discard = 0;\n"
                                   "		var GlobalArray = new Array();\n"
                                   "		var TypeArray = new Array();\n"
                                   "		var TimeArray = new Array();\n"
                                   "		var IndexArray = new Array();\n"
                                   "		var LabelArray = new Array();\n"
                                   "		for(var i = 0; i < Frames.length; i++)\n"
                                   "		{\n"
                                   "			var Frame_ = Frames[i];	\n"
                                   "			Frame_.LogStart[nLog] = TimeArray.length;\n"
                                   "			var FrameDiscard = (ThreadGpu[nLog] ? Frame_.frameendgpu : Frame_.frameend) + 33;//if "
                                   "timestamps are more than 33ms after current frame, we assume buffer has wrapped.\n"
                                   "			var tt = Frame_.tt[nLog];\n"
                                   "			var ts = Frame_.ts[nLog];\n"
                                   "			var ti = Frame_.ti[nLog];\n"
                                   "			var tl = Frame_.tl[nLog];\n"
                                   "			var len = tt.length;\n"
                                   "			var DiscardLast = 0;\n"
                                   "			for(var xx = 0; xx < len; ++xx)\n"
                                   "			{\n"
                                   "				var Skip = (tt[xx] == 4) ? DiscardLast : ts[xx] > FrameDiscard;\n"
                                   "				if(Skip)\n"
                                   "				{\n"
                                   "					Discard++;\n"
                                   "					DiscardLast = 1;\n"
                                   "				}\n"
                                   "				else\n"
                                   "				{\n"
                                   "					DiscardLast = 0;\n"
                                   "					GlobalArray.push(TypeArray.length);\n"
                                   "					TypeArray.push(tt[xx]);\n"
                                   "					TimeArray.push(ts[xx]);\n"
                                   "					IndexArray.push(ti[xx]);\n"
                                   "\n"
                                   "					// Use label after the region instead of the region name for some regions\n"
                                   "					var Label = null;\n"
                                   "					if(xx + 1 < len && tt[xx] == 1 && tt[xx+1] == 3 && TimerInfo[ti[xx]].namelabel)\n"
                                   "					{\n"
                                   "						Label = tl[ti[xx+1]];\n"
                                   "					}\n"
                                   "\n"
                                   "					LabelArray.push(Label);\n"
                                   "				}\n"
                                   "			}\n"
                                   "			Frame_.LogEnd[nLog] = TimeArray.length;\n"
                                   "		}\n"
                                   "		g_GlobalArray[nLog] = GlobalArray;\n"
                                   "		g_TypeArray[nLog] = TypeArray;\n"
                                   "		g_TimeArray[nLog] = TimeArray;\n"
                                   "		g_IndexArray[nLog] = IndexArray;\n"
                                   "		g_LabelArray[nLog] = LabelArray;\n"
                                   "		if(Discard)\n"
                                   "		{\n"
                                   "			console.log(\'discarded \' + Discard + \' markers from \' + ThreadNames[nLog]);\n"
                                   "		}\n"
                                   "	}\n"
                                   "	MakeLod(0, MinDelta, g_GlobalArray, LogStartArray);\n"
                                   "	ProfileLeave();\n"
                                   "}\n"
                                   "\n"
                                   "function PreprocessFindFirstFrames()\n"
                                   "{\n"
                                   "	ProfileEnter(\"PreprocesFindFirstFrames\");\n"
                                   "	//create arrays that show how far back we need to start search in order to get all markers.\n"
                                   "	var nNumLogs = Frames[0].ts.length;\n"
                                   "	for(var i = 0; i < Frames.length; i++)\n"
                                   "	{\n"
                                   "		Frames[i].FirstFrameIndex = new Array(nNumLogs);\n"
                                   "	}\n"
                                   "\n"
                                   "	var StackPos = 0;\n"
                                   "	var Stack = Array(20);\n"
                                   "	g_MaxStack = Array(nNumLogs);\n"
                                   "	\n"
                                   "	for(nLog = 0; nLog < nNumLogs; nLog++)\n"
                                   "	{\n"
                                   "		var MaxStack = 0;\n"
                                   "		StackPos = 0;\n"
                                   "		for(var i = 0; i < Frames.length; i++)\n"
                                   "		{\n"
                                   "			var Frame_ = Frames[i];			\n"
                                   "			var tt = Frame_.tt[nLog];\n"
                                   "			var count = tt.length;\n"
                                   "\n"
                                   "			var FirstFrame = i;\n"
                                   "			if(StackPos>0)\n"
                                   "			{\n"
                                   "				FirstFrame = Stack[0];\n"
                                   "			}\n"
                                   "			Frames[i].FirstFrameIndex[nLog] = FirstFrame;\n"
                                   "\n"
                                   "			for(var j = 0; j < count; j++)\n"
                                   "			{\n"
                                   "				var type = tt[j];\n"
                                   "				if(type == 1)\n"
                                   "				{\n"
                                   "					Stack[StackPos] = i;//store the frame which it comes from\n"
                                   "					StackPos++;\n"
                                   "					if(StackPos > MaxStack)\n"
                                   "					{\n"
                                   "						MaxStack = StackPos;\n"
                                   "					}\n"
                                   "				}\n"
                                   "				else if(type == 0)\n"
                                   "				{\n"
                                   "					if(StackPos>0)\n"
                                   "					{\n"
                                   "						StackPos--;\n"
                                   "					}\n"
                                   "				}\n"
                                   "			}\n"
                                   "		}\n"
                                   "		g_MaxStack[nLog] = MaxStack;\n"
                                   "	}\n"
                                   "	ProfileLeave();\n"
                                   "}\n"
                                   "function PreprocessMeta()\n"
                                   "{\n"
                                   "	MetaLengths = Array(MetaNames.length);\n"
                                   "	MetaLengthsAvg = Array(MetaNames.length);\n"
                                   "	MetaLengthsMax = Array(MetaNames.length);\n"
                                   "	for(var i = 0; i < MetaNames.length; ++i)\n"
                                   "	{\n"
                                   "		MetaLengths[i] = MetaNames[i].length+1;\n"
                                   "		MetaLengthsAvg[i] = MetaNames[i].length+5;\n"
                                   "		MetaLengthsMax[i] = MetaNames[i].length+5;\n"
                                   "		if(MetaLengths[i]<12)\n"
                                   "			MetaLengths[i] = 12;\n"
                                   "		if(MetaLengthsAvg[i]<12)\n"
                                   "			MetaLengthsAvg[i] = 12;\n"
                                   "		if(MetaLengthsMax[i]<12)\n"
                                   "			MetaLengthsMax[i] = 12;\n"
                                   "	}\n"
                                   "	for(var i = 0; i < TimerInfo.length; ++i)\n"
                                   "	{\n"
                                   "		var Timer = TimerInfo[i];\n"
                                   "		for(var j = 0; j < MetaNames.length; ++j)\n"
                                   "		{\n"
                                   "			var Len = FormatMeta(Timer.meta[j],0).length + 2;\n"
                                   "			var LenAvg = FormatMeta(Timer.meta[j],2).length + 2;\n"
                                   "			var LenMax = FormatMeta(Timer.meta[j],0).length + 2;\n"
                                   "			if(Len > MetaLengths[j])\n"
                                   "			{\n"
                                   "				MetaLengths[j] = Len;\n"
                                   "			}\n"
                                   "			if(LenAvg > MetaLengthsAvg[j])\n"
                                   "			{\n"
                                   "				MetaLengthsAvg[j] = LenAvg;\n"
                                   "			}\n"
                                   "			if(LenMax > MetaLengthsMax[j])\n"
                                   "			{\n"
                                   "				MetaLengthsMax[j] = LenMax;\n"
                                   "			}\n"
                                   "		}\n"
                                   "	}\n"
                                   "}\n"
                                   "\n"
                                   "function Preprocess()\n"
                                   "{\n"
                                   "	var ProfileModeOld = ProfileMode;\n"
                                   "	ProfileMode = 1;\n"
                                   "	ProfileModeClear();\n"
                                   "	ProfileEnter(\"Preprocess\");\n"
                                   "	PreprocessCalculateAllTimers();\n"
                                   "	PreprocessFindFirstFrames();\n"
                                   "	PreprocessGlobalArray();\n"
                                   "	PreprocessLods();\n"
                                   "	PreprocessMeta();\n"
                                   "	PreprocessContextSwitchCache();\n"
                                   "	ProfileLeave();\n"
                                   "	ProfileModeDump();\n"
                                   "	ProfileMode = ProfileModeOld;\n"
                                   "	Initialized = 1;\n"
                                   "}\n"
                                   "\n"
                                   "InitGroups();\n"
                                   "ReadCookie();\n"
                                   "MeasureFont()\n"
                                   "InitThreadMenu();\n"
                                   "InitGroupMenu();\n"
                                   "InitFrameInfo();\n"
                                   "UpdateThreadMenu();\n"
                                   "ResizeCanvas();\n"
                                   "Preprocess();\n"
                                   "OnPageReady();\n"
                                   "Draw(1);\n"
                                   "AutoRedraw();\n"
                                   "\n"
                                   "</script>\n"
                                   "</body>\n"
                                   "</html>\n"
                                   "";

const size_t g_ProfileHtml_end_3_size = sizeof(g_ProfileHtml_end_3);
const char*  g_ProfileHtml_end[] = {
    &g_ProfileHtml_end_0[0],
    &g_ProfileHtml_end_1[0],
    &g_ProfileHtml_end_2[0],
    &g_ProfileHtml_end_3[0],
};
size_t g_ProfileHtml_end_sizes[] = {
    sizeof(g_ProfileHtml_end_0),
    sizeof(g_ProfileHtml_end_1),
    sizeof(g_ProfileHtml_end_2),
    sizeof(g_ProfileHtml_end_3),
};
size_t g_ProfileHtml_end_count = 4;
#endif // PROFILE_EMBED_HTML

/// end file generated from  microprofile.html
